Discussion:
CVS commit: src/lib/libc
(too old to reply)
Roland Illig
2024-06-08 09:51:43 UTC
Permalink
libc: Pacify lint on aarch64.
+++ src/lib/libc/stdlib/Makefile.inc Fri Jun 7 20:50:13 2024
+# lint(1) spuriously complains about `*s == CHAR_MAX' even though *s
+# has type char.
+LINTFLAGS.strfmon.c += -X 230
I guess the "spuriously" here means "on platforms where 'char' is
unsigned", not "sometimes on the same platform, unpredictably".

When CHAR_MAX is defined as 0xff, lint assumes that the same constant
with the same value is used on other platforms as well, thus the
warning. This is due to lint's -p flag for portability checks.

Lint does not warn if the constant is defined as a character constant,
so '\xff' instead of 0xff would work, but I don't know what else would
be affected if the definition of CHAR_MAX were changed.

Ideally, lint would not warn about this expression, but since lint only
looks at the preprocessed translation unit, it cannot know that the 0xff
comes from CHAR_MAX and thus is fine. Practically, suppressing the
warning in this particular case makes sense.

Any ideas how to resolve this situation?

Roland


--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Taylor R Campbell
2024-06-08 17:29:53 UTC
Permalink
Date: Sat, 8 Jun 2024 11:51:43 +0200
libc: Pacify lint on aarch64.
+++ src/lib/libc/stdlib/Makefile.inc Fri Jun 7 20:50:13 2024
+# lint(1) spuriously complains about `*s == CHAR_MAX' even though *s
+# has type char.
+LINTFLAGS.strfmon.c += -X 230
I guess the "spuriously" here means "on platforms where 'char' is
unsigned", not "sometimes on the same platform, unpredictably".
Correct.
Lint does not warn if the constant is defined as a character constant,
so '\xff' instead of 0xff would work, but I don't know what else would
be affected if the definition of CHAR_MAX were changed.
Might work but I'm reluctant to try without extensive testing on a lot
of compilers in a lot of environments. E.g., does that work in C89?
Ideally, lint would not warn about this expression, but since lint only
looks at the preprocessed translation unit, it cannot know that the 0xff
comes from CHAR_MAX and thus is fine. Practically, suppressing the
warning in this particular case makes sense.
Any ideas how to resolve this situation?
No brilliant ideas, sorry, other than to teach lint to track
provenance of constants through macro expansion. That's why I just
disabled the warning for this case.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Loading...