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

Commit4868e44

Browse files
committed
Ensure that snprintf.c's fmtint() doesn't overflow when printing INT64_MIN.
This isn't actually a live bug, as the output happens to be thesame. But it upsets tools like UBSan, which makes it worthwhile tofix.As it's an issue without practical consequences, don't backpatch.Author: Andres FreundDiscussion:https://postgr.es/m/20180928001121.hhx5n6dsygqxr5wu@alap3.anarazel.de
1 parent9a3cebe commit4868e44

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

‎src/port/snprintf.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,7 @@ fmtint(long long value, char type, int forcesign, int leftjust,
10071007
PrintfTarget*target)
10081008
{
10091009
unsigned long longbase;
1010+
unsigned long longuvalue;
10101011
intdosign;
10111012
constchar*cvt="0123456789abcdef";
10121013
intsignvalue=0;
@@ -1045,7 +1046,9 @@ fmtint(long long value, char type, int forcesign, int leftjust,
10451046

10461047
/* Handle +/- */
10471048
if (dosign&&adjust_sign((value<0),forcesign,&signvalue))
1048-
value=-value;
1049+
uvalue=-(uint64)value;
1050+
else
1051+
uvalue= (uint64)value;
10491052

10501053
/*
10511054
* SUS: the result of converting 0 with an explicit precision of 0 is no
@@ -1056,8 +1059,6 @@ fmtint(long long value, char type, int forcesign, int leftjust,
10561059
else
10571060
{
10581061
/* make integer string */
1059-
unsigned long longuvalue= (unsigned long long)value;
1060-
10611062
do
10621063
{
10631064
convert[sizeof(convert)- (++vallen)]=cvt[uvalue %base];

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp