Skip to content

Commit

Permalink
driver_settings: don't strdup(NULL)
Browse files Browse the repository at this point in the history
* This is not allowed by strdup POSIX specs and GCC may use its builtin
strdup which doesn't check for it.
* also refactor parse_driver_settings_string to create the
settings_handle using settings_new, to reduce code duplication.
  • Loading branch information
pulkomandy committed Jan 14, 2015
1 parent 9873130 commit 0687a01
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/system/libroot/os/driver_settings.cpp
Expand Up @@ -820,21 +820,16 @@ load_driver_settings_file(int fd)
void *
parse_driver_settings_string(const char *settingsString)
{
if (settingsString == NULL)
return NULL;

// we simply copy the whole string to use it as our internal buffer
char *text = strdup(settingsString);
if (settingsString == NULL || text != NULL) {
settings_handle *handle
= (settings_handle*)malloc(sizeof(settings_handle));
if (handle != NULL) {
handle->magic = SETTINGS_MAGIC;
handle->text = text;

if (parse_settings(handle) == B_OK)
return handle;

free(handle);
}
free(text);
if (text != NULL) {
settings_handle *handle = new_settings(text, NULL);
if (handle == NULL)
free(text);
return handle;
}

return NULL;
Expand Down

0 comments on commit 0687a01

Please sign in to comment.