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 791532 - Implicit declaration of function ‘memcmp’ in gtestutils.h
Implicit declaration of function ‘memcmp’ in gtestutils.h
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.48.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2017-12-12 17:31 UTC by Stefan Mächler
Modified: 2017-12-13 16:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
bug.c (206 bytes, text/plain)
2017-12-12 17:31 UTC, Stefan Mächler
  Details
gtestutils: Add missing include (717 bytes, patch)
2017-12-13 13:15 UTC, Philip Withnall
committed Details | Review

Description Stefan Mächler 2017-12-12 17:31:39 UTC
Created attachment 365451 [details]
bug.c

The 'g_assert_cmpmem()' macro defined in the 'glib/gtestutils.h' header, uses the 'memcmp()' function of the stdlib without including the 'string.h' header.

Thus, the attached test program (bug.c), does not compile when the '-Werror' option is enabled. As shown by the following compiler error messages:

$ gcc -Werror -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -lglib-2.0 bug.c
In file included from /usr/include/glib-2.0/glib.h:82:0,
                 from bug.c:1:
bug.c: In function ‘main’:
/usr/include/glib-2.0/glib/gtestutils.h:77:55: error: implicit declaration of function ‘memcmp’ [-Werror=implicit-function-declaration]
                                              else if (memcmp (__m1, __m2, __l1) != 0) \
                                                       ^
bug.c:8:5: note: in expansion of macro ‘g_assert_cmpmem’
     g_assert_cmpmem(foo, sizeof(foo), bar, sizeof(bar));
     ^
cc1: all warnings being treated as errors

I know, this might be a really easy bug fix. I am new to glib and I am not sure if it is okay just to add the '#include <string.h>' statement to the 'glib/gtestutils.h' header or if there is some more abstraction needed like a 'g_memcmp()' function or what ever?

Cheers,
Stefan
Comment 1 Philip Withnall 2017-12-13 13:15:52 UTC
Created attachment 365487 [details] [review]
gtestutils: Add missing include

memcmp() is used, which is declared in string.h. Include that.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Comment 2 Emmanuele Bassi (:ebassi) 2017-12-13 13:17:13 UTC
Review of attachment 365487 [details] [review]:

:thumbsup:
Comment 3 Philip Withnall 2017-12-13 13:28:56 UTC
Thanks for the fast patch review.

Attachment 365487 [details] pushed as 6a597f9 - gtestutils: Add missing include
Comment 4 Stefan Mächler 2017-12-13 16:03:46 UTC
Review of attachment 365487 [details] [review]:

That was fast and exactly what I would have done as well. Thank you.