[patch] Fix compiler warnings throughout
Eric Blake
eblake@redhat.com
Fri Aug 10 16:08:00 GMT 2012
On 08/08/2012 05:04 AM, Corinna Vinschen wrote:
> Hi,
>
> I just applied the below patch. The idea was to be able to compile
> newlib with gcc options set to -Wall -Werror to better support porting
> to new targets. So the below patch fixes all problems which showed up
> when running with these options, like uninitialized variables, suggested
> parenthesis and braces, as well as real bug which was only uncovered by
> using these options in freopen.c
>
> Please have a look if something is broken for your target now. I don't
> think so, but still...
>
> Index: libc/posix/collate.c
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/posix/collate.c,v
> retrieving revision 1.3
> diff -u -p -r1.3 collate.c
> --- libc/posix/collate.c 25 May 2011 18:41:10 -0000 1.3
> +++ libc/posix/collate.c 8 Aug 2012 11:01:26 -0000
> @@ -117,24 +117,26 @@ __collate_substitute(s)
> const u_char *s;
> {
> int dest_len, len, nlen;
> - int delta = strlen(s);
> + int delta = strlen((const char *) s);
> u_char *dest_str = NULL;
>
> if(s == NULL || *s == '\0')
> - return __collate_strdup("");
> + return __collate_strdup((u_char *) "");
> delta += delta / 8;
> - dest_str = malloc(dest_len = delta);
> + dest_str = (u_char *) malloc(dest_len = delta);
Is this one necessary? I can see why you added the other casts, though.
> @@ -364,6 +364,9 @@ sopno stopst;
> char *ssp; /* start of string matched by subsubRE */
> char *sep; /* end of string matched by subsubRE */
> char *oldssp; /* previous ssp */
> +/* dp is only used for assertion testing which, for some reason, is not
> + recognized as usage. */
> +#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
Does this need to be guarded by a minimum gcc version filter?
> Index: libc/stdio/freopen.c
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/stdio/freopen.c,v
> retrieving revision 1.26
> diff -u -p -r1.26 freopen.c
> --- libc/stdio/freopen.c 30 May 2012 08:58:42 -0000 1.26
> +++ libc/stdio/freopen.c 8 Aug 2012 11:01:27 -0000
> @@ -208,7 +208,7 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp)
> if (HASLB (fp))
> FREELB (ptr, fp);
> fp->_lb._size = 0;
> - fp->_flags & ~__SORD;
> + fp->_flags &= ~__SORD;
Oh my. Yep, this is correct.
> Index: libc/string/strcasestr.c
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/string/strcasestr.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 strcasestr.c
> --- libc/string/strcasestr.c 19 Aug 2011 16:58:20 -0000 1.4
> +++ libc/string/strcasestr.c 8 Aug 2012 11:01:28 -0000
> @@ -84,6 +84,8 @@ QUICKREF
> (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \
> && ((h_l) = (j) + (n_l)))
> # define CANON_ELEMENT(c) tolower (c)
> +/* strncasecmp uses signed char, CMP_FUNC is expected to use unsigned char. */
> +#pragma GCC diagnostic ignored "-Wpointer-sign"
Another case of guarding with a gcc version guard.
Everything else seemed decent on inspection.
--
Eric Blake eblake@redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://sourceware.org/pipermail/newlib/attachments/20120810/c4ed21f4/attachment.sig>
More information about the Newlib
mailing list