Skip to content

Commit acd1aae

Browse files
committed
DEBUG: invalidate getenv() calls when the next one is called
This is a crude, and incomplete, way to diagnose getenv() issues where the return value is not used transiently. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent cc7f43e commit acd1aae

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

compat/mingw.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2079,11 +2079,14 @@ char *mingw_getenv(const char *name)
20792079

20802080
len_value = len_value * 3 + 1;
20812081
/* We cannot use xcalloc() here because that uses getenv() itself */
2082-
value = calloc(len_value, sizeof(char));
2082+
//value = calloc(len_value, sizeof(char));
2083+
value = calloc(len_value < 16 ? 16 : len_value, sizeof(char));
20832084
if (!value)
20842085
die("Out of memory, (tried to allocate %u bytes)", len_value);
20852086
xwcstoutf(value, w_value, len_value);
20862087

2088+
/* Be mean and invalidate the previous getenv() result */
2089+
{ int offset = !strcmp("GIT_COMMITTER_EMAIL", name) || !strcmp("GIT_AUTHOR_EMAIL", name) ? 2 : (!strcmp("GIT_COMMITTER_DATE", name) || !strcmp("GIT_AUTHOR_DATE", name) ? 3 : 1); char *p = values[(value_counter + ARRAY_SIZE(values) - offset) % ARRAY_SIZE(values)]; if (p) xsnprintf(p, 16, "NONONONONONONO!"); }
20872090
/*
20882091
* We return `value` which is an allocated value and the caller is NOT
20892092
* expecting to have to free it, so we keep a round-robin array,

0 commit comments

Comments
 (0)