[gimp/wip/smcv/2-10-path-max] qbist: Allocate path dynamically instead of using a PATH_MAX-sized buffer




commit 9a7789abc72d12f26314ac7b58eea9a3d88b7827
Author: Simon McVittie <smcv debian org>
Date:   Wed Apr 7 17:38:27 2021 +0100

    qbist: Allocate path dynamically instead of using a PATH_MAX-sized buffer
    
    On modern Unix systems, PATH_MAX is more of a guideline than an actual
    limit. In particular, Linux arbitrarily defines PATH_MAX as 4096 but
    can actually have paths longer than this, and on Hurd the macro isn't
    defined at all.
    
    This turns out to be the only place in GIMP 2.10.x where PATH_MAX is
    used outside #ifdef ENABLE_RELOCATABLE_RESOURCES.
    
    Loosely based on commit d659bb12, but without using new API.
    
    Bug-Debian: https://bugs.debian.org/934077
    Signed-off-by: Simon McVittie <smcv debian org>

 plug-ins/common/qbist.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
---
diff --git a/plug-ins/common/qbist.c b/plug-ins/common/qbist.c
index 5b4a6ed67f..101273a558 100644
--- a/plug-ins/common/qbist.c
+++ b/plug-ins/common/qbist.c
@@ -83,7 +83,7 @@ typedef struct
 {
   ExpInfo  info;
   gint     oversampling;
-  gchar    path[PATH_MAX];
+  gchar   *path;
 } QbistInfo;
 
 
@@ -542,6 +542,7 @@ run (const gchar      *name,
           gimp_displays_flush ();
         }
 
+      g_clear_pointer (&qbist_info.path, g_free);
       g_rand_free (gr);
     }
 
@@ -728,17 +729,17 @@ dialog_load (GtkWidget *widget,
                                            -1);
   gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
 
-  gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), qbist_info.path);
+  if (qbist_info.path)
+    gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), qbist_info.path);
 
   if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
     {
       gchar *name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
 
-      strncpy (qbist_info.path, name, PATH_MAX - 1);
+      g_free (qbist_info.path);
+      qbist_info.path = name;
       load_data (qbist_info.path);
 
-      g_free (name);
-
       dialog_new_variations (NULL, NULL);
       dialog_update_previews (NULL, NULL);
     }
@@ -773,16 +774,16 @@ dialog_save (GtkWidget *widget,
   gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
                                                   TRUE);
 
-  gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), qbist_info.path);
+  if (qbist_info.path)
+    gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), qbist_info.path);
 
   if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
     {
       gchar *name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
 
-      strncpy (qbist_info.path, name, PATH_MAX - 1);
+      g_free (qbist_info.path);
+      qbist_info.path = name;
       save_data (qbist_info.path);
-
-      g_free (name);
     }
 
   gtk_widget_destroy (dialog);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]