Menu

#1 bug in the code of argp-standalone-1.3/strndup.c

Done
None
Medium
Defect
2017-02-25
2014-10-02
Anonymous
No

Originally created by: avne...@gmail.com

The following piece of code contains wrong check for error condition:
---- 
  r = malloc(size);

  if (size)
    {
      memcpy(r, s, size-1);
      r[size-1] = '\0';
    }
  return r;
----
The author probably intended to check "if (r)"

Also, notice, that the semantic of your code has "off by one" bug when relating to the semantic of the original GNU function.  See man strndup - they will allocate size+1 bytes and not just size bytes as you do.

HTH,
Avner

Discussion

  • Chris Jackson

    Chris Jackson - 2017-02-25

    Thanks!

    Chris

     
  • Chris Jackson

    Chris Jackson - 2017-02-25
    • Description has changed:

    Diff:

    
    
    • status: New --> Fixed
     
  • Chris Jackson

    Chris Jackson - 2017-02-25
    • status: Fixed --> Done
    • assigned_to: Chris Jackson
     

Log in to post a comment.

MongoDB Logo MongoDB