Skip to content

Commit

Permalink
UTF8_CHK_SKIP: eliminate casting away const
Browse files Browse the repository at this point in the history
Seen with:

  ./Configure -des -Dusedevel -Accflags=-Wcast-qual

mathoms.c: In function ‘Perl_utf8_to_uvchr’:
utf8.h:804:53: warning: cast discards ‘const’ qualifier from pointer target type
 [-Wcast-qual]
  804 |            (UNLIKELY(s[0] == '\0') ? 1 : my_strnlen((char *) (s), UTF8SK
IP(s)))
      |                                                     ^
embed.h:792:87: note: in definition of macro ‘utf8_to_uvchr_buf_helper’
  792 | # define utf8_to_uvchr_buf_helper(a,b,c)        Perl_utf8_to_uvchr_buf_h
elper(aTHX_ a,b,c)
      |
              ^
mathoms.c:970:12: note: in expansion of macro ‘utf8_to_uvchr_buf’
  970 |     return utf8_to_uvchr_buf(s, s + UTF8_CHK_SKIP(s), retlen);
      |            ^~~~~~~~~~~~~~~~~
mathoms.c:970:37: note: in expansion of macro ‘UTF8_CHK_SKIP’
  970 |     return utf8_to_uvchr_buf(s, s + UTF8_CHK_SKIP(s), retlen);
      |                                     ^~~~~~~~~~~~~

mathoms.c seems to be the only user of this macro.

This came up when reviewing Perl#22271
  • Loading branch information
tonycoz committed Jun 17, 2024
1 parent dac174e commit 71fe650
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ C<L</UTF8_SAFE_SKIP>>, for example when interfacing with a C library.
*/

#define UTF8_CHK_SKIP(s) \
(UNLIKELY(s[0] == '\0') ? 1 : my_strnlen((char *) (s), UTF8SKIP(s)))
(UNLIKELY(s[0] == '\0') ? 1 : my_strnlen((const char *) (s), UTF8SKIP(s)))
/*
=for apidoc Am|STRLEN|UTF8_SAFE_SKIP|char* s|char* e
Expand Down

0 comments on commit 71fe650

Please sign in to comment.