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

Commit595a0ea

Browse files
committed
Rationalize snprintf.c's handling of "ll" formats.
Although all known platforms define "long long" as 64 bits, it still feelsa bit shaky to be using "va_arg(args, int64)" to pull out an argument thatthe caller thought was declared "long long". The reason it was coded likethis, way back in commit3311c76, was to work around the possibility thatthe compiler had no type named "long long" --- and, at the time, that itmaybe didn't have 64-bit ints at all. Now that we're requiring compilersto support C99, those concerns are moot. Let's make the code clearer andmore bulletproof by writing "long long" where we mean "long long".This does introduce a hazard that we'd inefficiently use 128-bit arithmeticto convert plain old integers. The way to tackle that would be to providetwo versions of fmtint(), one for "long long" and one for narrower types.Since, as of today, no platforms require that, we won't bother with theextra code for now.Discussion:https://postgr.es/m/1680.1538587115@sss.pgh.pa.us
1 parent6d842be commit595a0ea

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

‎src/port/snprintf.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ typedef union
157157
{
158158
inti;
159159
longl;
160-
int64ll;
160+
long longll;
161161
doubled;
162162
char*cptr;
163163
}PrintfArgValue;
@@ -319,7 +319,7 @@ static bool find_arguments(const char *format, va_list args,
319319
staticvoidfmtstr(constchar*value,intleftjust,intminlen,intmaxwidth,
320320
intpointflag,PrintfTarget*target);
321321
staticvoidfmtptr(void*value,PrintfTarget*target);
322-
staticvoidfmtint(int64value,chartype,intforcesign,
322+
staticvoidfmtint(long longvalue,chartype,intforcesign,
323323
intleftjust,intminlen,intzpad,intprecision,intpointflag,
324324
PrintfTarget*target);
325325
staticvoidfmtchar(intvalue,intleftjust,intminlen,PrintfTarget*target);
@@ -390,7 +390,7 @@ dopr(PrintfTarget *target, const char *format, va_list args)
390390
intforcesign;
391391
intfmtpos;
392392
intcvalue;
393-
int64numvalue;
393+
long longnumvalue;
394394
doublefvalue;
395395
char*strvalue;
396396
PrintfArgValueargvalues[PG_NL_ARGMAX+1];
@@ -603,7 +603,7 @@ dopr(PrintfTarget *target, const char *format, va_list args)
603603
else
604604
{
605605
if (longlongflag)
606-
numvalue=va_arg(args,int64);
606+
numvalue=va_arg(args,longlong);
607607
elseif (longflag)
608608
numvalue=va_arg(args,long);
609609
else
@@ -626,7 +626,7 @@ dopr(PrintfTarget *target, const char *format, va_list args)
626626
if (have_dollar)
627627
{
628628
if (longlongflag)
629-
numvalue= (uint64)argvalues[fmtpos].ll;
629+
numvalue= (unsigned long long)argvalues[fmtpos].ll;
630630
elseif (longflag)
631631
numvalue= (unsigned long)argvalues[fmtpos].l;
632632
else
@@ -635,7 +635,7 @@ dopr(PrintfTarget *target, const char *format, va_list args)
635635
else
636636
{
637637
if (longlongflag)
638-
numvalue= (uint64)va_arg(args,int64);
638+
numvalue= (unsigned long long)va_arg(args,longlong);
639639
elseif (longflag)
640640
numvalue= (unsigned long)va_arg(args,long);
641641
else
@@ -944,7 +944,7 @@ find_arguments(const char *format, va_list args,
944944
argvalues[i].l=va_arg(args,long);
945945
break;
946946
caseATYPE_LONGLONG:
947-
argvalues[i].ll=va_arg(args,int64);
947+
argvalues[i].ll=va_arg(args,longlong);
948948
break;
949949
caseATYPE_DOUBLE:
950950
argvalues[i].d=va_arg(args,double);
@@ -1002,11 +1002,11 @@ fmtptr(void *value, PrintfTarget *target)
10021002
}
10031003

10041004
staticvoid
1005-
fmtint(int64value,chartype,intforcesign,intleftjust,
1005+
fmtint(long longvalue,chartype,intforcesign,intleftjust,
10061006
intminlen,intzpad,intprecision,intpointflag,
10071007
PrintfTarget*target)
10081008
{
1009-
uint64base;
1009+
unsigned long longbase;
10101010
intdosign;
10111011
constchar*cvt="0123456789abcdef";
10121012
intsignvalue=0;
@@ -1056,7 +1056,7 @@ fmtint(int64 value, char type, int forcesign, int leftjust,
10561056
else
10571057
{
10581058
/* make integer string */
1059-
uint64uvalue= (uint64)value;
1059+
unsigned long longuvalue= (unsigned long long)value;
10601060

10611061
do
10621062
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp