After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 787772 - Consistently use g_stat and GStatBuf (instead of "struct stat" and plain "stat")
Consistently use g_stat and GStatBuf (instead of "struct stat" and plain "stat")
Product: gtk+
Classification: Platform
Component: .General
Other Windows
: Normal normal
: ---
Assigned To: gtk-bugs
Depends on:
Reported: 2017-09-16 22:21 UTC by Eduard Braun
Modified: 2018-05-02 19:07 UTC
See Also:
GNOME target: ---
GNOME version: ---

Replace "stat struct" with "GStatBuf" and "stat" with "g_stat" to fix breakages on Windows (11.50 KB, patch)
2017-09-16 22:21 UTC, Eduard Braun
none Details | Review
Replace "stat struct" with "GStatBuf" and "stat" with "g_stat" to fix breakages on Windows v2 (11.21 KB, patch)
2018-01-13 22:14 UTC, Eduard Braun
accepted-commit_now Details | Review

Description Eduard Braun 2017-09-16 22:21:07 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.

Comment 1 Daniel Boles 2017-09-19 09:11:23 UTC
It seems worth mentioning that MSYS2 has applied this patch downstream:
Comment 2 Emmanuele Bassi (:ebassi) 2018-01-13 14:51:25 UTC
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.
Comment 3 Eduard Braun 2018-01-13 22:14:36 UTC
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.
Comment 4 Emmanuele Bassi (:ebassi) 2018-02-09 16:08:14 UTC
Review of attachment 366781 [details] [review]:

Looks good, now. Thanks!
Comment 5 GNOME Infrastructure Team 2018-05-02 19:07:33 UTC
-- 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: