driver_settings: don't strdup(NULL)
* 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.
This commit is contained in:
@@ -820,21 +820,16 @@ load_driver_settings_file(int fd)
|
|||||||
void *
|
void *
|
||||||
parse_driver_settings_string(const char *settingsString)
|
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
|
// we simply copy the whole string to use it as our internal buffer
|
||||||
char *text = strdup(settingsString);
|
char *text = strdup(settingsString);
|
||||||
if (settingsString == NULL || text != NULL) {
|
if (text != NULL) {
|
||||||
settings_handle *handle
|
settings_handle *handle = new_settings(text, NULL);
|
||||||
= (settings_handle*)malloc(sizeof(settings_handle));
|
if (handle == NULL)
|
||||||
if (handle != NULL) {
|
free(text);
|
||||||
handle->magic = SETTINGS_MAGIC;
|
return handle;
|
||||||
handle->text = text;
|
|
||||||
|
|
||||||
if (parse_settings(handle) == B_OK)
|
|
||||||
return handle;
|
|
||||||
|
|
||||||
free(handle);
|
|
||||||
}
|
|
||||||
free(text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user