When can a printf fail?

printf is one the fundamental libc functions, but when can it fail?  It can fail when the program output is being redirected to the disk, and the disk becomes full.

Does this mean we should check the return value of printf?  For absolutely robust code it would be nice, but I’ve never seen it adopted.  In production environments I have seen the *printf functions fail in glibc for unknown reasons under load.

3 responses to “When can a printf fail?

  1. Pingback: Casting printf to void « xorl %eax, %eax

  2. Pingback: Computer News and Security · Casting printf to void

  3. printf fails in glibc if the underlying write system call fails, or if it cannot allocate memory for the I/O buffer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s