develooper Front page | perl.perl5.porters | Postings from October 2016

utf8.c: Silence a compiler warning

Thread Next
From:
Andy Lester
Date:
October 18, 2016 02:28
Subject:
utf8.c: Silence a compiler warning
Message ID:
2B6CE3F8-B566-4581-B7E3-815C45F37E04@petdance.com
I was looking at this patch from a few days ago and it looks to me that the comment is incorrect about compiler warnings saying that adjusted_send was being used uninitialized.  There's nothing wrong with setting it to NULL, but it looks to me that without doing that, we are indeed using an uninitialized value, and I'm concerned that we might have had a bug that we just pasted over and didn't realize it.

Seems that there are only four instances of that string, unless I'm missing somewhere where there's preprocessor magic going on, or some goto path I missed.  Without that NULL at line 1000, looks to me like 1082 is an uninitialized use.

utf8.c
1000:    U8 * adjusted_send = NULL;  /* (Initialized to silence compilers' wrong
1082:    send = adjusted_send
1169:            adjusted_send = uvoffuni_to_utf8_flags(adjusted_s0, min_uv, 0);
1255:     * adjusted_send        normally is the same as 'send', but if adjusted_s0
1486:                                                                adjusted_send)))

Not sure if there's a better place to raise this.  I don't know that this is a bug, so didn't want to file a ticket.

Andy


commit 5ec712b17f589b0efc75ccd871d07947dd474a85
Author: Karl Williamson <khw@cpan.org>
Date:   Sat Oct 15 11:00:57 2016 -0600

    utf8.c: Silence a compiler warning
    
    Some compilers wrongly warn that this is used uninitialized.

diff --git a/utf8.c b/utf8.c
index 729650d..fb3acad 100644
--- a/utf8.c
+++ b/utf8.c
@@ -997,7 +997,8 @@ Perl_utf8n_to_uvchr_error(pTHX_ const U8 *s,
      * too short one.  Otherwise the first two are set to 's0' and 'send', and
      * the third not used at all */
     U8 * adjusted_s0 = (U8 *) s0;
-    U8 * adjusted_send;
+    U8 * adjusted_send = NULL;  /* (Initialized to silence compilers' wrong
+                                   warning) */
     UV uv_so_far = 0;   /* (Initialized to silence compilers' wrong warning) */
 
     PERL_ARGS_ASSERT_UTF8N_TO_UVCHR_ERROR;


--
Andy Lester => www.petdance.com


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About