Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence GCC 11 warnings #468

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion ext/json/ext/fbuffer/fbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ static void freverse(char *start, char *end)
}
}

#define FBUFFER_APPEND_LONG_BUFFER_SIZE 20

static long fltoa(long number, char *buf)
{
static char digits[] = "0123456789";
Expand All @@ -155,13 +157,14 @@ static long fltoa(long number, char *buf)
if (sign < 0) number = -number;
do *tmp++ = digits[number % 10]; while (number /= 10);
if (sign < 0) *tmp++ = '-';
if (tmp > buf + FBUFFER_APPEND_LONG_BUFFER_SIZE) UNREACHABLE;
Comment on lines 159 to +160
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition means that tmp overflowed.
Doesn't it result in another warning?

Suggested change
if (sign < 0) *tmp++ = '-';
if (tmp > buf + FBUFFER_APPEND_LONG_BUFFER_SIZE) UNREACHABLE;
if (tmp >= buf + FBUFFER_APPEND_LONG_BUFFER_SIZE) UNREACHABLE;
if (sign < 0) *tmp++ = '-';

freverse(buf, tmp - 1);
return tmp - buf;
}

static void fbuffer_append_long(FBuffer *fb, long number)
{
char buf[20];
char buf[FBUFFER_APPEND_LONG_BUFFER_SIZE];
unsigned long len = fltoa(number, buf);
fbuffer_append(fb, buf, len);
}
Expand Down