Commit 4d9e24d1 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

Better deal with NULL pointers.

CID 3 and 4 from the coverity.com scan.
parent 1f236ba1
Loading
Loading
Loading
Loading
+14 −8
Original line number Diff line number Diff line
@@ -282,6 +282,7 @@ static const char * ContentTypeForFilename (const char *filename,
       text/plain so we don't actually need to set this: */
    contenttype = HTTPPOST_CONTENTTYPE_DEFAULT;

  if(filename) { /* in case a NULL was passed in */
    for(i=0; i<sizeof(ctts)/sizeof(ctts[0]); i++) {
      if(strlen(filename) >= strlen(ctts[i].extension)) {
        if(strequal(filename +
@@ -292,6 +293,7 @@ static const char * ContentTypeForFilename (const char *filename,
        }
      }
    }
  }
  /* we have a contenttype by now */
  return contenttype;
}
@@ -315,10 +317,14 @@ static char *memdup(const char *src, size_t buffer_length)

  if (buffer_length)
    length = buffer_length;
  else {
  else if(src) {
    length = strlen(src);
    add = TRUE;
  }
  else
    /* no length and a NULL src pointer! */
    return strdup((char *)"");

  buffer = (char*)malloc(length+add);
  if (!buffer)
    return NULL; /* fail */