Skip to main content
printf("%s", (void*) NULL) is UB, so doesn't need testing. Thanks @chux.
Source Link
Toby Speight
  • 81.7k
  • 14
  • 101
  • 308

Some small items, additional to the great review by Chux.

  • You don't seem to use anything from <assert.h> or <float.h>, so no need to include those.

  • The missing features are not documented anywhere, so we have to guess what subset of printf() is supported.

  • Test cases are missing for ±infinity±∞ and not-a-number values with the %f specifier and for null pointers with the %s specifier.

  • Precision specifiers don't work properly with %s:

      myprintf("%.5s", "abcdefg");  // crashes
    
  • Unnecessary obfuscation: *(s_p+1) is much more recognisable when written as s_p[1].

  • The fallthrough from case '.' to default causes the second conversion specifier to be printed literally in this example (and could be even more serious if the second conversion were %%):

      myprintf("%.1f%f\n", 1.0, 0.0);
    

Some small items, additional to the great review by Chux.

  • You don't seem to use anything from <assert.h> or <float.h>, so no need to include those.

  • The missing features are not documented anywhere, so we have to guess what subset of printf() is supported.

  • Test cases are missing for ±infinity and not-a-number values with the %f specifier and for null pointers with the %s specifier.

  • Precision specifiers don't work properly with %s:

      myprintf("%.5s", "abcdefg");  // crashes
    
  • Unnecessary obfuscation: *(s_p+1) is much more recognisable when written as s_p[1].

  • The fallthrough from case '.' to default causes the second conversion specifier to be printed literally in this example (and could be even more serious if the second conversion were %%):

      myprintf("%.1f%f\n", 1.0, 0.0);
    

Some small items, additional to the great review by Chux.

  • You don't seem to use anything from <assert.h> or <float.h>, so no need to include those.

  • The missing features are not documented anywhere, so we have to guess what subset of printf() is supported.

  • Test cases are missing for ±∞ and not-a-number values with the %f specifier.

  • Precision specifiers don't work properly with %s:

      myprintf("%.5s", "abcdefg");  // crashes
    
  • Unnecessary obfuscation: *(s_p+1) is much more recognisable when written as s_p[1].

  • The fallthrough from case '.' to default causes the second conversion specifier to be printed literally in this example (and could be even more serious if the second conversion were %%):

      myprintf("%.1f%f\n", 1.0, 0.0);
    
Source Link
Toby Speight
  • 81.7k
  • 14
  • 101
  • 308

Some small items, additional to the great review by Chux.

  • You don't seem to use anything from <assert.h> or <float.h>, so no need to include those.

  • The missing features are not documented anywhere, so we have to guess what subset of printf() is supported.

  • Test cases are missing for ±infinity and not-a-number values with the %f specifier and for null pointers with the %s specifier.

  • Precision specifiers don't work properly with %s:

      myprintf("%.5s", "abcdefg");  // crashes
    
  • Unnecessary obfuscation: *(s_p+1) is much more recognisable when written as s_p[1].

  • The fallthrough from case '.' to default causes the second conversion specifier to be printed literally in this example (and could be even more serious if the second conversion were %%):

      myprintf("%.1f%f\n", 1.0, 0.0);