From e62ccbf7707f62b8056a963b6bd01507fbf02817 Mon Sep 17 00:00:00 2001 From: Rudi Heitbaum Date: Thu, 5 Mar 2026 03:05:22 +0000 Subject: [PATCH] unix: do not cast to char variables that are const char Fix the casting of const char varaibles with const char returns from functions, when the data being returned is not being modified. Includes the part revert of "unix: fix compilation warnings with GCC 15" This reverts commit 50ed2fd7bdd42830ff7327773f62540899b0e9a3. --- include/uv.h | 2 +- src/unix/internal.h | 8 ++++---- src/unix/linux.c | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/uv.h b/include/uv.h index 3ba24e2ff..da0634555 100644 --- a/include/uv.h +++ b/include/uv.h @@ -1209,7 +1209,7 @@ struct uv_cpu_times_s { }; struct uv_cpu_info_s { - char* model; + const char* model; int speed; struct uv_cpu_times_s cpu_times; }; diff --git a/src/unix/internal.h b/src/unix/internal.h index dcd5f95e2..80fe41f8e 100644 --- a/src/unix/internal.h +++ b/src/unix/internal.h @@ -470,12 +470,12 @@ UV_UNUSED(static void uv__update_time(uv_loop_t* loop)) { loop->time = uv__hrtime(UV_CLOCK_FAST) / 1000000; } -UV_UNUSED(static char* uv__basename_r(const char* path)) { - char* s; +UV_UNUSED(static const char* uv__basename_r(const char* path)) { + const char* s; - s = strrchr((char*) path, '/'); + s = strrchr(path, '/'); if (s == NULL) - return (char*) path; + return path; return s + 1; } diff --git a/src/unix/linux.c b/src/unix/linux.c index 2b55e1ba3..110964884 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -1639,7 +1639,7 @@ done: int uv_resident_set_memory(size_t* rss) { char buf[1024]; - char* s; + const char* s; long val; int rc; int i; @@ -1900,7 +1900,7 @@ nocpuinfo: c = *cpus + cpu; (*ci)[i++] = (uv_cpu_info_t) { - .model = (char*) p + c->model * sizeof(*model), + .model = p + c->model * sizeof(*model), .speed = c->freq / 1000, /* Note: sysconf(_SC_CLK_TCK) is fixed at 100 Hz, * therefore the multiplier is always 1000/100 = 10. @@ -2371,10 +2371,10 @@ next: return 0; } -static char* uv__cgroup1_find_cpu_controller(const char* cgroup, +static const char* uv__cgroup1_find_cpu_controller(const char* cgroup, int* cgroup_size) { /* Seek to the cpu controller line. */ - char* cgroup_cpu = strstr((char*) cgroup, ":cpu,"); + const char* cgroup_cpu = strstr(cgroup, ":cpu,"); if (cgroup_cpu != NULL) { /* Skip the controller prefix to the start of the cgroup path. */ @@ -2391,7 +2391,7 @@ static int uv__get_cgroupv1_constrained_cpu(const char* cgroup, char path[256]; char buf[1024]; int cgroup_size; - char* cgroup_cpu; + const char* cgroup_cpu; long long period_length; long long quota_per_period;