30
30
#include "printf_base.h"
31
31
32
32
#include <assert.h>
33
- #include <stdarg.h>
34
33
#include <stdio.h>
35
34
#include <string.h>
36
35
#include <unistd.h>
@@ -145,23 +144,18 @@ DEFINE_PRINT_FLOATS (double)
145
144
/**************************************************************************/
146
145
147
146
#define FORWARD_BUFFER (SIZE ) \
148
- buffer += SIZE; \
149
- if (buffer_size < SIZE) \
147
+ buffer += ( SIZE); \
148
+ if (buffer_size < ( SIZE)) \
150
149
{ \
151
150
POCL_MSG_ERR ( \
152
151
"printf error: exhausted arguments before format string end\n"); \
153
152
return -1; \
154
153
} \
155
- buffer_size -= SIZE;
154
+ buffer_size -= ( SIZE) ;
156
155
157
156
uint32_t
158
157
__pocl_printf_format_full (param_t * p , char * buffer , uint32_t buffer_size )
159
158
{
160
-
161
- char bf [BUFSIZE ];
162
- for (unsigned i = 0 ; i < BUFSIZE ; ++ i )
163
- bf [i ] = 0 ;
164
- p -> bf = bf ;
165
159
char ch = 0 ;
166
160
167
161
/* fetch & decode the control dword */
@@ -365,7 +359,7 @@ __pocl_printf_format_full (param_t *p, char *buffer, uint32_t buffer_size)
365
359
DEBUG_PRINTF (("[printf:precision=%d]\n" , precision ));
366
360
367
361
/* Vector specifier */
368
- uint32_t vector_length = 0 ;
362
+ int32_t vector_length = 0 ;
369
363
if (ch == 'v' )
370
364
{
371
365
ch = * format ++ ;
@@ -377,7 +371,7 @@ __pocl_printf_format_full (param_t *p, char *buffer, uint32_t buffer_size)
377
371
"printf error: vector-length is zero\n" );
378
372
return -1 ;
379
373
}
380
- if (vector_length > ( UINT32_MAX - 9 ) / 10 )
374
+ if (vector_length < 0 )
381
375
{
382
376
POCL_MSG_ERR (
383
377
"printf error: vector-length overflow\n" );
@@ -391,7 +385,7 @@ __pocl_printf_format_full (param_t *p, char *buffer, uint32_t buffer_size)
391
385
|| vector_length == 16 ))
392
386
{
393
387
POCL_MSG_ERR (
394
- "printf error: unrecognize vector length (%u )\n" ,
388
+ "printf error: unrecognized vector length (%d )\n" ,
395
389
vector_length );
396
390
return -1 ;
397
391
}
@@ -608,8 +602,8 @@ __pocl_printf_format_full (param_t *p, char *buffer, uint32_t buffer_size)
608
602
return -1 ;
609
603
}
610
604
DEBUG_PRINTF (("[printf:char4]\n" ));
611
- bf [0 ] = (char )* buffer ;
612
- bf [1 ] = 0 ;
605
+ p -> bf [0 ] = (char )* buffer ;
606
+ p -> bf [1 ] = 0 ;
613
607
/* char is always promoted to int32 */
614
608
FORWARD_BUFFER (sizeof (int32_t ));
615
609
__pocl_printf_putchw (p );
749
743
pocl_flush_printf_buffer (char * buffer , uint32_t buffer_size )
750
744
{
751
745
param_t p = { 0 };
746
+ char bf [BUFSIZE ];
747
+ memset (bf , 0 , BUFSIZE );
748
+ p .bf = bf ;
752
749
753
750
char result [IMM_FLUSH_BUFFER_SIZE ];
754
751
p .printf_buffer = result ;
0 commit comments