1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

Better deal with NULL pointers.

CID 3 and 4 from the coverity.com scan.
This commit is contained in:
Daniel Stenberg 2007-03-31 21:01:18 +00:00
parent 1f236ba108
commit 4d9e24d1e4

View File

@ -282,13 +282,15 @@ static const char * ContentTypeForFilename (const char *filename,
text/plain so we don't actually need to set this: */ text/plain so we don't actually need to set this: */
contenttype = HTTPPOST_CONTENTTYPE_DEFAULT; contenttype = HTTPPOST_CONTENTTYPE_DEFAULT;
for(i=0; i<sizeof(ctts)/sizeof(ctts[0]); i++) { if(filename) { /* in case a NULL was passed in */
if(strlen(filename) >= strlen(ctts[i].extension)) { for(i=0; i<sizeof(ctts)/sizeof(ctts[0]); i++) {
if(strequal(filename + if(strlen(filename) >= strlen(ctts[i].extension)) {
strlen(filename) - strlen(ctts[i].extension), if(strequal(filename +
ctts[i].extension)) { strlen(filename) - strlen(ctts[i].extension),
contenttype = ctts[i].type; ctts[i].extension)) {
break; contenttype = ctts[i].type;
break;
}
} }
} }
} }
@ -315,10 +317,14 @@ static char *memdup(const char *src, size_t buffer_length)
if (buffer_length) if (buffer_length)
length = buffer_length; length = buffer_length;
else { else if(src) {
length = strlen(src); length = strlen(src);
add = TRUE; add = TRUE;
} }
else
/* no length and a NULL src pointer! */
return strdup((char *)"");
buffer = (char*)malloc(length+add); buffer = (char*)malloc(length+add);
if (!buffer) if (!buffer)
return NULL; /* fail */ return NULL; /* fail */