comparison th_string.c @ 281:0c70dcfb6796

Remember to initialize th_printf_ctx.ipos to 0!
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 22 Feb 2016 12:01:29 +0200
parents 454f0d37d94b
children 2b76cc316205
comparison
equal deleted inserted replaced
280:454f0d37d94b 281:0c70dcfb6796
379 int ret; 379 int ret;
380 th_printf_ctx ctx; 380 th_printf_ctx ctx;
381 ctx.buf = buf; 381 ctx.buf = buf;
382 ctx.size = size; 382 ctx.size = size;
383 ctx.pos = 0; 383 ctx.pos = 0;
384 ctx.ipos = 0;
384 385
385 ret = th_vprintf_do(&ctx, th_pbuf_vputch, fmt, ap); 386 ret = th_vprintf_do(&ctx, th_pbuf_vputch, fmt, ap);
386 387
387 if (ctx.pos < size) 388 if (ctx.pos < size)
388 buf[ctx.pos] = 0; 389 buf[ctx.pos] = 0;
416 { 417 {
417 #ifdef TH_USE_INTERNAL_SPRINTF 418 #ifdef TH_USE_INTERNAL_SPRINTF
418 th_printf_ctx ctx; 419 th_printf_ctx ctx;
419 ctx.data = (void *) fh; 420 ctx.data = (void *) fh;
420 ctx.pos = 0; 421 ctx.pos = 0;
422 ctx.ipos = 0;
421 423
422 return th_vprintf_do(&ctx, th_stdio_vputch, fmt, ap); 424 return th_vprintf_do(&ctx, th_stdio_vputch, fmt, ap);
423 #else 425 #else
424 return vfprintf(fh, fmt, ap); 426 return vfprintf(fh, fmt, ap);
425 #endif 427 #endif
435 va_list ap; 437 va_list ap;
436 va_start(ap, fmt); 438 va_start(ap, fmt);
437 #ifdef TH_USE_INTERNAL_SPRINTF 439 #ifdef TH_USE_INTERNAL_SPRINTF
438 ctx.data = (void *) fh; 440 ctx.data = (void *) fh;
439 ctx.pos = 0; 441 ctx.pos = 0;
442 ctx.ipos = 0;
443
440 ret = th_vprintf_do(&ctx, th_stdio_vputch, fmt, ap); 444 ret = th_vprintf_do(&ctx, th_stdio_vputch, fmt, ap);
441 #else 445 #else
442 ret = fprintf(fh, fmt, ap); 446 ret = fprintf(fh, fmt, ap);
443 #endif 447 #endif
444 va_end(ap); 448 va_end(ap);