GNOME Bugzilla – Bug 787772
Consistently use g_stat and GStatBuf (instead of "struct stat" and plain "stat")
Last modified: 2018-05-02 19:07:33 UTC
Created attachment 359904 [details] [review] Replace "stat struct" with "GStatBuf" and "stat" with "g_stat" to fix breakages on Windows The attached patch replaces "stat struct" with "GStatBuf" [1] and "stat" with "g_stat" [2]. While this should be identical on *nix it resolves some serious breakages on Windows: - Field widths of "struct stat" are not constant on Windows, see [3]. If the stat function does not match the stat struct used it will cause overwrites and undefined behavior - The Windows stat function needs a properly encoded filename. However we happily feed it UTF-8 in many places watching it choke to death. (I'm not sure what the idea was here...) This patch should solve those issues resulting in application bugs like [4] (GtkRecentChooser failing for files with non-ASCII characters). As for gtk3 a previous patch from bug 660730 already fixed most of these. However I still found some remaining occurrences of "struct stat" in the codebase, so if desired I can look into providing a patch for those, too. [1] https://developer.gnome.org/glib/stable/glib-File-Utilities.html#GStatBuf [2] https://developer.gnome.org/glib/stable/glib-File-Utilities.html#g-stat [3] https://msdn.microsoft.com/en-us/library/14h5k7ff.aspx [4] https://bugs.launchpad.net/inkscape/+bug/629608
It seems worth mentioning that MSYS2 has applied this patch downstream: https://github.com/Alexpux/MINGW-packages/commit/e652682263f0ed6df32d5cb49d0b5882dcb9e4b1
Review of attachment 359904 [details] [review]: ::: gtk+-2.24.31a/gtk/gtksearchenginesimple.c @@ +199,3 @@ static int +search_visit_func (const char *fpath, + const GStatBuf *sb, We're using ftw(), here, so there's really no need to use GStatBuf. ::: gtk+-2.24.31a/gtk/updateiconcache.c @@ +79,3 @@ +static int check_dir_mtime (const char *dir, + const GStatBuf *sb, Same as above: this is a callback from ftw(). ::: gtk+-2.24.31a/modules/printbackends/cups/gtkcupsutils.c @@ +717,3 @@ { gchar length[255]; + GStatBuf data_info; CUPS is not available on Windows, so there's no point in using GStatBuf. The `data_info` variable is used with fstat() later on.
Created attachment 366781 [details] [review] Replace "stat struct" with "GStatBuf" and "stat" with "g_stat" to fix breakages on Windows v2 Thanks for the review. Updated patch is attached.
Review of attachment 366781 [details] [review]: Looks good, now. Thanks!
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gtk/issues/914.