From 0f3dc2ee15c6bb1a005728d3d1107cd4da6e0c7f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 20 Mar 2020 18:48:28 +0000 Subject: [PATCH 1/2] zsh/rlimits: Make known_resources const in set_resinfo() but not elsewhere. --- Src/Builtins/rlimits.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Src/Builtins/rlimits.c b/Src/Builtins/rlimits.c index aa9b9dd48..c3c031fff 100644 --- a/Src/Builtins/rlimits.c +++ b/Src/Builtins/rlimits.c @@ -49,8 +49,13 @@ typedef struct resinfo_T { char* descr; /* used by ulimit builtin */ } resinfo_T; -/* table of known resources */ -static const resinfo_T known_resources[] = { +/* table of known resources + * + * Not const since set_resinfo() may change some of the letters to 'N' in case + * of collisions. However, all access should be through the "resinfo" global, + * which exposes this as a const array. + */ +static resinfo_T known_resources[] = { {RLIMIT_CPU, "cputime", ZLIMTYPE_TIME, 1, 't', "cpu time (seconds)"}, {RLIMIT_FSIZE, "filesize", ZLIMTYPE_MEMORY, 512, @@ -175,14 +180,15 @@ static void set_resinfo(void) { int i; + resinfo_T **resinfo_mutable; - resinfo = (const resinfo_T **)zshcalloc(RLIM_NLIMITS*sizeof(resinfo_T *)); + resinfo_mutable = (resinfo_T **)zshcalloc(RLIM_NLIMITS*sizeof(resinfo_T *)); for (i=0; iunit = 1; info->opt = 'N'; info->descr = buf; - resinfo[i] = info; + resinfo_mutable[i] = info; } } + + resinfo = (const resinfo_T **) resinfo_mutable; } /**/