2026-05-08 Paul Eggert <eggert@cs.ucla.edu>
+ Avoid string literal type confusion
+ Instead of ‘... (char *) "abc" ...’, which is a bit confusing as
+ "abc" is already of type char *, use ‘static char const s[] =
+ "abc"; ... (char *) s .... This pacifices -Wuseless-cast.
+ * lib/boot-time.c (get_boot_time_uncached):
+ * lib/time_rz.c (save_abbr):
+ * tests/test-posix_spawn-chdir.c (test):
+ * tests/test-posix_spawn-fchdir.c (test):
+ * tests/test-unsetenv.c (main):
+ Redo with named string as described above.
+
times-tests: pacify -Wuseless-cast
* tests/test-times.c (tms2ms): New function.
(main): Use it to simplify printing and avoid need for casts.
Solaris' utmpname returns 1 upon success -- which is contrary
to what the GNU libc version does. In addition, older GNU libc
versions are actually void. */
- UTMP_NAME_FUNCTION ((char *) UTMP_FILE);
+ static char const utmp_file[] = UTMP_FILE;
+ UTMP_NAME_FUNCTION ((char *) utmp_file);
SET_UTMP_ENT ();
{
# if HAVE_STRUCT_TM_TM_ZONE
char const *zone = tm->tm_zone;
- char *zone_copy = (char *) "";
+ static char const mt[] = "";
+ char *zone_copy = (char *) mt;
/* No need to replace null zones, or zones within the struct tm. */
if (!zone || ((char *) tm <= zone && zone < (char *) (tm + 1)))
static void
test (const char *pwd_prog)
{
- char *argv[2] = { (char *) "pwd", NULL };
+ static char const pwd[] = "pwd";
+ char *argv[2] = { (char *) pwd, NULL };
int ifd[2];
sigset_t blocked_signals;
sigset_t fatal_signal_set;
static void
test (const char *pwd_prog)
{
- char *argv[2] = { (char *) "pwd", NULL };
+ static char const pwd[] = "pwd";
+ char *argv[2] = { (char *) pwd, NULL };
/* The name of a directory that most likely is accessible. */
#if defined __ANDROID__
#define KNOWNDIR "/proc"
static char entry[] = "b=2";
/* Test removal when multiple entries present. */
- ASSERT (putenv ((char *) "a=1") == 0);
+ static char const a_equals_1[] = "a=1";
+ ASSERT (putenv ((char *) a_equals_1) == 0);
ASSERT (putenv (entry) == 0);
entry[0] = 'a'; /* Unspecified what getenv("a") would be at this point. */
ASSERT (unsetenv ("a") == 0); /* Both entries will be removed. */