Skip to content

printf("%s", NULL) - crash #63

Closed

Description

@mad-rain

Hi!

Some placeholder should be used for NULL %s argument to prevent printf from crash:

      case 's' : {
        const char* p = va_arg(va, char*);
        if (!p) p = "(null)"; // please add this

Activity

  1. noomio commented on Oct 17, 2019

    @noomio

    I just came here to add just that!

        const char* p = va_arg(va, char*);
        p = (p == NULL) ? "(null)" : p;
    
  2. self-assigned this
    on Jan 1, 2020
  3. dev-zzo commented on Apr 22, 2020

    @dev-zzo

    This should be an optional behaviour as in many embedded situations address zero is a perfectly valid one.

  4. eyalroz commented on Jun 30, 2021

    @eyalroz
    Collaborator

    @dev-zzo : What about %p, then? Should that also not have an option to print 0 as 0 rather than (nil) on such platforms?

  5. added a commit that references this issue on Jun 30, 2021
    f849d41
  6. eyalroz commented on Jun 30, 2021

    @eyalroz
    Collaborator

    So, this issue is now fixed on my fork. @dev-zzo , @noomio , @mpaland Please have a look and voice your opinion about the behavior with null/0 pointers.

    Also, @mpaland : Can you explain the code's "partiality" to the use of _out_rev? That is, what's the benefit of printing characters backwards like that? I used it too in the changes I made for this issue, but I was just following the pattern.

  7. added a commit that references this issue on Jul 1, 2021
    e4baa6a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions