Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit01e51ed

Browse files
committed
Replace static buf with a stack-allocated one in 'seg' extension
The buffer is used only locally within the function. Also, theinitialization to '0' characters was unnecessary, the initial contentwere always overwritten with sprintf(). I don't understand why it wasdone that way, but it's been like that since forever.In the passing, change from sprintf() to snprintf(). The buffer waslong enough so sprintf() was fine, but this makes it more obvious thatthere's no risk of a buffer overflow.Reviewed-by: Robert HaasDiscussion:https://www.postgresql.org/message-id/7f86e06a-98c5-4ce3-8ec9-3885c8de0358@iki.fi
1 parentda8a587 commit01e51ed

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

‎contrib/seg/segparse.y‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ static bool seg_atof(char *value, float *result, struct Node *escontext);
2929

3030
staticintsig_digits(constchar *value);
3131

32-
staticchar strbuf[25] = {
33-
'0','0','0','0','0',
34-
'0','0','0','0','0',
35-
'0','0','0','0','0',
36-
'0','0','0','0','0',
37-
'0','0','0','0','\0'
38-
};
39-
4032
%}
4133

4234
/* BISON Declarations*/
@@ -69,11 +61,13 @@ static char strbuf[25] = {
6961

7062
range: boundary PLUMIN deviation
7163
{
64+
charstrbuf[25];
65+
7266
result->lower = $1.val - $3.val;
7367
result->upper = $1.val + $3.val;
74-
sprintf(strbuf,"%g", result->lower);
68+
snprintf(strbuf,sizeof(strbuf),"%g", result->lower);
7569
result->l_sigd =Max(sig_digits(strbuf),Max($1.sigd, $3.sigd));
76-
sprintf(strbuf,"%g", result->upper);
70+
snprintf(strbuf,sizeof(strbuf),"%g", result->upper);
7771
result->u_sigd =Max(sig_digits(strbuf),Max($1.sigd, $3.sigd));
7872
result->l_ext ='\0';
7973
result->u_ext ='\0';

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp