mailing list of musl libc
 help / color / mirror / Atom feed
* [musl] Warnings in fnmatch implementation
@ 2021-05-02 12:11 Vincent Torri
  2021-05-02 15:18 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Vincent Torri @ 2021-05-02 12:11 UTC (permalink / raw)
  To: musl

Hello


when compiling fnmatch.c, I have there following warnings :


fnmatch.c: In function 'str_next':
fnmatch.c:34:13: warning: comparison of integer expressions of
different signedness: 'char' and 'unsigned int' [-Wsign-compare]
   34 |  if (str[0] >= 128U) {
      |             ^~
fnmatch.c: In function 'pat_next':
fnmatch.c:87:13: warning: comparison of integer expressions of
different signedness: 'char' and 'unsigned int' [-Wsign-compare]
   87 |  if (pat[0] >= 128U) {
      |             ^~
fnmatch.c: In function 'match_bracket':
fnmatch.c:129:24: warning: comparison of integer expressions of
different signedness: 'unsigned int' and 'int' [-Wsign-compare]
  129 |     if ((unsigned)k-wc <= wc2-wc ||
      |                        ^~
fnmatch.c:130:28: warning: comparison of integer expressions of
different signedness: 'unsigned int' and 'int' [-Wsign-compare]
  130 |         (unsigned)kfold-wc <= wc2-wc)
      |                            ^~
fnmatch.c:150:10: warning: comparison of integer expressions of
different signedness: 'char' and 'unsigned int' [-Wsign-compare]
  150 |   if (*p < 128U) {
      |          ^
fnmatch.c: In function 'fnmatch_internal':
fnmatch.c:232:13: warning: comparison of integer expressions of
different signedness: 'char' and 'unsigned int' [-Wsign-compare]
  232 |   if (s[-1] < 128U || MB_CUR_MAX==1) s--;
      |             ^

All the 128U can be replaced by just 128, and (unsigned) by just (int)

Maybe it is worth fixing them

best regards

Vincent Torri

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [musl] Warnings in fnmatch implementation
  2021-05-02 12:11 [musl] Warnings in fnmatch implementation Vincent Torri
@ 2021-05-02 15:18 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2021-05-02 15:18 UTC (permalink / raw)
  To: Vincent Torri; +Cc: musl

On Sun, May 02, 2021 at 02:11:03PM +0200, Vincent Torri wrote:
> Hello
> 
> 
> when compiling fnmatch.c, I have there following warnings :
> 
> 
> fnmatch.c: In function 'str_next':
> fnmatch.c:34:13: warning: comparison of integer expressions of
> different signedness: 'char' and 'unsigned int' [-Wsign-compare]
>    34 |  if (str[0] >= 128U) {
>       |             ^~
> fnmatch.c: In function 'pat_next':
> fnmatch.c:87:13: warning: comparison of integer expressions of
> different signedness: 'char' and 'unsigned int' [-Wsign-compare]
>    87 |  if (pat[0] >= 128U) {
>       |             ^~
> fnmatch.c: In function 'match_bracket':
> fnmatch.c:129:24: warning: comparison of integer expressions of
> different signedness: 'unsigned int' and 'int' [-Wsign-compare]
>   129 |     if ((unsigned)k-wc <= wc2-wc ||
>       |                        ^~
> fnmatch.c:130:28: warning: comparison of integer expressions of
> different signedness: 'unsigned int' and 'int' [-Wsign-compare]
>   130 |         (unsigned)kfold-wc <= wc2-wc)
>       |                            ^~
> fnmatch.c:150:10: warning: comparison of integer expressions of
> different signedness: 'char' and 'unsigned int' [-Wsign-compare]
>   150 |   if (*p < 128U) {
>       |          ^
> fnmatch.c: In function 'fnmatch_internal':
> fnmatch.c:232:13: warning: comparison of integer expressions of
> different signedness: 'char' and 'unsigned int' [-Wsign-compare]
>   232 |   if (s[-1] < 128U || MB_CUR_MAX==1) s--;
>       |             ^
> 
> All the 128U can be replaced by just 128, and (unsigned) by just (int)

They definitely can't be replaced with just 128. Changing them to 128
changes the meaning of the expression and introduces a serious bug
(prevents handling of any non-ASCII characters on archs where plain
char is a signed type). For example -64 < 128 is true but -64 < 128U
is false.

Rich

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-02 15:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-02 12:11 [musl] Warnings in fnmatch implementation Vincent Torri
2021-05-02 15:18 ` Rich Felker

mailing list of musl libc

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.vuxu.org/musl

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 musl musl/ https://inbox.vuxu.org/musl \
		musl@inbox.vuxu.org
	public-inbox-index musl

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.musl


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/musl/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git