Re: fix some gcc warnings
Pádraig Brady wrote: > > 2016-10-16 Bruno Haible> > > > Fix some "gcc -Wall" warnings. > > * tests/test-ffsl.c (main): Use variable x, not i. > > * tests/test-posix_spawn3.c (parent_main): Consider the return value of > > freopen. > > * tests/test-sethostname1.c (main): Explicitly ignore the return value > > of sethostname. > > +1 > thanks OK, I pushed this.
Re: fix some gcc warnings
On 16/10/16 16:01, Bruno Haible wrote: > Hi, > > When I compile a gnulib testdir with "gcc -Wall", I see the following warnings > (among others): > > test-ffsl.c: In function 'main': > test-ffsl.c:44:12: warning: unused variable 'x' [-Wunused-variable] > > test-posix_spawn3.c: In function 'parent_main': > test-posix_spawn3.c:78:11: warning: ignoring return value of 'freopen', > declared with attribute warn_unused_result [-Wunused-result] > > test-sethostname1.c: In function 'main': > test-sethostname1.c:34:17: warning: ignoring return value of 'sethostname', > declared with attribute warn_unused_result [-Wunused-result] > > Here's a proposed fix for them. > > > 2016-10-16 Bruno Haible> > Fix some "gcc -Wall" warnings. > * tests/test-ffsl.c (main): Use variable x, not i. > * tests/test-posix_spawn3.c (parent_main): Consider the return value of > freopen. > * tests/test-sethostname1.c (main): Explicitly ignore the return value > of sethostname. > > diff --git a/tests/test-ffsl.c b/tests/test-ffsl.c > index e903509..117bc4a 100644 > --- a/tests/test-ffsl.c > +++ b/tests/test-ffsl.c > @@ -44,8 +44,8 @@ main (int argc, char *argv[]) >long int x; >int i; > > - for (i = -128; i <= 128; i++) > -ASSERT (ffsl (i) == naive (i)); > + for (x = -128; x <= 128; x++) > +ASSERT (ffsl (x) == naive (x)); >for (i = 0; i < NBITS; i++) > { >ASSERT (ffsl (1UL << i) == naive (1UL << i)); > diff --git a/tests/test-posix_spawn3.c b/tests/test-posix_spawn3.c > index 90745fd..f2a699c 100644 > --- a/tests/test-posix_spawn3.c > +++ b/tests/test-posix_spawn3.c > @@ -75,7 +75,11 @@ parent_main (void) > } > >/* Avoid reading from our stdin, as it could block. */ > - freopen ("/dev/null", "rb", stdin); > + if (freopen ("/dev/null", "rb", stdin) == NULL) > +{ > + perror ("cannot redirect stdin"); > + return 1; > +} > >/* Test whether posix_spawn_file_actions_addopen with this file name > actually works, but spawning a child that reads from this file. */ > diff --git a/tests/test-sethostname1.c b/tests/test-sethostname1.c > index 5ed6a83..08441f3 100644 > --- a/tests/test-sethostname1.c > +++ b/tests/test-sethostname1.c > @@ -30,8 +30,11 @@ main () >/* Some code that has a link-time dependency to the sethostname() function > and that is likely not optimized away by compilers. */ >if (do_dangerous_things) > -/* Never executed. */ > -sethostname ("oprah", 5); > +{ > + /* Never executed. */ > + int ret = sethostname ("oprah", 5); > + (void) ret; > +} > >return 0; > } > > > +1 thanks
fix some gcc warnings
Hi, When I compile a gnulib testdir with "gcc -Wall", I see the following warnings (among others): test-ffsl.c: In function 'main': test-ffsl.c:44:12: warning: unused variable 'x' [-Wunused-variable] test-posix_spawn3.c: In function 'parent_main': test-posix_spawn3.c:78:11: warning: ignoring return value of 'freopen', declared with attribute warn_unused_result [-Wunused-result] test-sethostname1.c: In function 'main': test-sethostname1.c:34:17: warning: ignoring return value of 'sethostname', declared with attribute warn_unused_result [-Wunused-result] Here's a proposed fix for them. 2016-10-16 Bruno HaibleFix some "gcc -Wall" warnings. * tests/test-ffsl.c (main): Use variable x, not i. * tests/test-posix_spawn3.c (parent_main): Consider the return value of freopen. * tests/test-sethostname1.c (main): Explicitly ignore the return value of sethostname. diff --git a/tests/test-ffsl.c b/tests/test-ffsl.c index e903509..117bc4a 100644 --- a/tests/test-ffsl.c +++ b/tests/test-ffsl.c @@ -44,8 +44,8 @@ main (int argc, char *argv[]) long int x; int i; - for (i = -128; i <= 128; i++) -ASSERT (ffsl (i) == naive (i)); + for (x = -128; x <= 128; x++) +ASSERT (ffsl (x) == naive (x)); for (i = 0; i < NBITS; i++) { ASSERT (ffsl (1UL << i) == naive (1UL << i)); diff --git a/tests/test-posix_spawn3.c b/tests/test-posix_spawn3.c index 90745fd..f2a699c 100644 --- a/tests/test-posix_spawn3.c +++ b/tests/test-posix_spawn3.c @@ -75,7 +75,11 @@ parent_main (void) } /* Avoid reading from our stdin, as it could block. */ - freopen ("/dev/null", "rb", stdin); + if (freopen ("/dev/null", "rb", stdin) == NULL) +{ + perror ("cannot redirect stdin"); + return 1; +} /* Test whether posix_spawn_file_actions_addopen with this file name actually works, but spawning a child that reads from this file. */ diff --git a/tests/test-sethostname1.c b/tests/test-sethostname1.c index 5ed6a83..08441f3 100644 --- a/tests/test-sethostname1.c +++ b/tests/test-sethostname1.c @@ -30,8 +30,11 @@ main () /* Some code that has a link-time dependency to the sethostname() function and that is likely not optimized away by compilers. */ if (do_dangerous_things) -/* Never executed. */ -sethostname ("oprah", 5); +{ + /* Never executed. */ + int ret = sethostname ("oprah", 5); + (void) ret; +} return 0; }
thread: fix some gcc warnings
The statement gl_thread_t t = gl_thread_self (); gives a gcc warning about assignment from a pointer to an integer. This fixes it: 2011-07-08 Bruno Haible br...@clisp.org thread: Avoid gcc warnings when using gl_thread_self(). * lib/glthread/thread.h (gl_thread_self): Return a pthread_t, not a 'void *'. (gl_thread_self_pointer): Update. --- lib/glthread/thread.h.orig Fri Jul 8 13:22:25 2011 +++ lib/glthread/thread.h Fri Jul 8 13:11:25 2011 @@ -161,9 +161,9 @@ extern const gl_thread_t gl_null_thread; # else # define gl_thread_self() \ - (pthread_in_use () ? (void *) pthread_self () : NULL) + (pthread_in_use () ? pthread_self () : (pthread_t) NULL) # define gl_thread_self_pointer() \ - gl_thread_self () + (pthread_in_use () ? (void *) pthread_self () : NULL) # endif # define gl_thread_exit(RETVAL) \ (pthread_in_use () ? pthread_exit (RETVAL) : 0) -- In memoriam Jean Moulin http://en.wikipedia.org/wiki/Jean_Moulin
Re: thread: fix some gcc warnings
On 07/08/2011 05:27 AM, Bruno Haible wrote: The statement gl_thread_t t = gl_thread_self (); gives a gcc warning about assignment from a pointer to an integer. This fixes it: 2011-07-08 Bruno Haible br...@clisp.org thread: Avoid gcc warnings when using gl_thread_self(). * lib/glthread/thread.h (gl_thread_self): Return a pthread_t, not a 'void *'. (gl_thread_self_pointer): Update. --- lib/glthread/thread.h.origFri Jul 8 13:22:25 2011 +++ lib/glthread/thread.h Fri Jul 8 13:11:25 2011 @@ -161,9 +161,9 @@ extern const gl_thread_t gl_null_thread; # else # define gl_thread_self() \ - (pthread_in_use () ? (void *) pthread_self () : NULL) + (pthread_in_use () ? pthread_self () : (pthread_t) NULL) This not portable. POSIX allows pthread_t to be a non-pointer type, so you can't necessarily cast NULL to pthread_t. -- Eric Blake ebl...@redhat.com+1-801-349-2682 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: thread: fix some gcc warnings
Eric Blake wrote: - (pthread_in_use () ? (void *) pthread_self () : NULL) + (pthread_in_use () ? pthread_self () : (pthread_t) NULL) This not portable. POSIX allows pthread_t to be a non-pointer type, so you can't necessarily cast NULL to pthread_t. Yes, and the only platform that defines pthread_t to a non-scalar type is pthreads-win32, and it is handled 5 lines above that code. Bruno -- In memoriam Jean Moulin http://en.wikipedia.org/wiki/Jean_Moulin