msvcrt: Don't add 0x prefix while printing 0 with printf.

This commit is contained in:
Piotr Caban 2014-03-20 16:20:26 +01:00 committed by Alexandre Julliard
parent b6db22da3b
commit 2693ce1a25
2 changed files with 39 additions and 3 deletions

View file

@ -265,9 +265,11 @@ static inline void FUNC_NAME(pf_integer_conv)(APICHAR *buf, int buf_len,
}
i = 0;
if(x==0 && flags->Precision)
buf[i++] = '0';
else {
if(x == 0) {
flags->Alternate = 0;
if(flags->Precision)
buf[i++] = '0';
} else {
while(x != 0) {
j = (ULONGLONG)x%base;
x = (ULONGLONG)x/base;

View file

@ -329,18 +329,52 @@ static void test_sprintf( void )
format = "%#012x";
r = sprintf(buffer,format,1);
ok(!strcmp(buffer,"0x0000000001"),"Hexadecimal zero-padded \"%s\"\n",buffer);
ok( r==12, "return count wrong\n");
r = sprintf(buffer,format,0);
ok(!strcmp(buffer,"000000000000"),"Hexadecimal zero-padded \"%s\"\n",buffer);
ok( r==12, "return count wrong\n");
format = "%#04.8x";
r = sprintf(buffer,format,1);
ok(!strcmp(buffer,"0x00000001"), "Hexadecimal zero-padded precision \"%s\"\n",buffer);
ok( r==10, "return count wrong\n");
r = sprintf(buffer,format,0);
ok(!strcmp(buffer,"00000000"), "Hexadecimal zero-padded precision \"%s\"\n",buffer);
ok( r==8, "return count wrong\n");
format = "%#-08.2x";
r = sprintf(buffer,format,1);
ok(!strcmp(buffer,"0x01 "), "Hexadecimal zero-padded not left-adjusted \"%s\"\n",buffer);
ok( r==8, "return count wrong\n");
r = sprintf(buffer,format,0);
ok(!strcmp(buffer,"00 "), "Hexadecimal zero-padded not left-adjusted \"%s\"\n",buffer);
ok( r==8, "return count wrong\n");
format = "%#.0x";
r = sprintf(buffer,format,1);
ok(!strcmp(buffer,"0x1"), "Hexadecimal zero-padded zero-precision \"%s\"\n",buffer);
ok( r==3, "return count wrong\n");
r = sprintf(buffer,format,0);
ok(!strcmp(buffer,""), "Hexadecimal zero-padded zero-precision \"%s\"\n",buffer);
ok( r==0, "return count wrong\n");
format = "%#08o";
r = sprintf(buffer,format,1);
ok(!strcmp(buffer,"00000001"), "Octal zero-padded \"%s\"\n",buffer);
ok( r==8, "return count wrong\n");
format = "%#o";
r = sprintf(buffer,format,1);
ok(!strcmp(buffer,"01"), "Octal zero-padded \"%s\"\n",buffer);
ok( r==2, "return count wrong\n");
r = sprintf(buffer,format,0);
ok(!strcmp(buffer,"0"), "Octal zero-padded \"%s\"\n",buffer);
ok( r==1, "return count wrong\n");
if (sizeof(void *) == 8)
{