Skip to content

Commit

Permalink
[agroal#337] Fix compilation problems
Browse files Browse the repository at this point in the history
As reported in CI test failures
<agroal#336 (comment)>
and
<agroal#336 (comment)>
the system does not compile under GCC 12 with `-Werror` option.

This commit fixes the string length problem reported by gcc.

Close agroal#337
  • Loading branch information
fluca1978 committed Dec 14, 2022
1 parent 305aa8a commit 8ae6072
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/libpgagroal/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -3781,7 +3781,7 @@ to_string(char* where, char* value)
bool has_double_quotes = false;
bool has_single_quotes = false;

if (!where || !value || strlen(value) > MISC_LENGTH)
if (!where || !value || strlen(value) >= MISC_LENGTH)
{
return 1;
}
Expand All @@ -3807,18 +3807,24 @@ to_string(char* where, char* value)

if (needs_quotes)
{
// there must be space for quotes
if (strlen(value) > MISC_LENGTH - 2 - 1)
{
return 1;
}

if (!has_single_quotes)
{
snprintf(where, MISC_LENGTH, "'%s'", value);
snprintf(where, MISC_LENGTH - 1, "'%s'", value);
}
else if (!has_double_quotes)
{
snprintf(where, MISC_LENGTH, "\"%s\"", value);
snprintf(where, MISC_LENGTH - 1, "\"%s\"", value);
}
}
else
{
snprintf(where, MISC_LENGTH, "%s", value);
snprintf(where, MISC_LENGTH - 1, "%s", value);
}

return 0;
Expand Down

0 comments on commit 8ae6072

Please sign in to comment.