mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
Use Size rather than int for storing strnlen's return
... in fe_memutils.c's pnstrdup(). strnlen() does return size_t, so it seems better to use the Size input parameter to store the return value rather than demote it to int and risk larger values being truncated. Pushing only to master as this doesn't seem like an actual problem. Fixing will hopefully prevent future LLM-triggered reports about this. Author: Chao Li <li.evan.chao@gmail.com> Discussion: https://postgr.es/m/0E717E09-809F-4BC4-B3B1-36BE729DBFAE@gmail.com
This commit is contained in:
@@ -151,7 +151,6 @@ char *
|
||||
pnstrdup(const char *in, Size size)
|
||||
{
|
||||
char *tmp;
|
||||
int len;
|
||||
|
||||
if (!in)
|
||||
{
|
||||
@@ -160,16 +159,16 @@ pnstrdup(const char *in, Size size)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
len = strnlen(in, size);
|
||||
tmp = malloc(len + 1);
|
||||
size = strnlen(in, size);
|
||||
tmp = malloc(size + 1);
|
||||
if (tmp == NULL)
|
||||
{
|
||||
fprintf(stderr, _("out of memory\n"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
memcpy(tmp, in, len);
|
||||
tmp[len] = '\0';
|
||||
memcpy(tmp, in, size);
|
||||
tmp[size] = '\0';
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user