cleanup asprintf return value being ignored warnings

This commit is contained in:
John Johansen 2009-07-24 23:47:46 +00:00
parent c8fa7815a6
commit 22d883b4d3
2 changed files with 25 additions and 16 deletions

View file

@ -786,21 +786,24 @@ int cache_fd = -1;
int sd_serialize_codomain(int option, struct codomain *cod)
{
int fd;
int error = 0, size, wsize;
int error = -ENOMEM, size, wsize;
sd_serialize *work_area;
char *filename = NULL;
switch (option) {
case OPTION_ADD:
asprintf(&filename, "%s/.load", subdomainbase);
if (asprintf(&filename, "%s/.load", subdomainbase) == -1)
goto exit;
fd = open(filename, O_WRONLY);
break;
case OPTION_REPLACE:
asprintf(&filename, "%s/.replace", subdomainbase);
if (asprintf(&filename, "%s/.replace", subdomainbase) == -1)
goto exit;
fd = open(filename, O_WRONLY);
break;
case OPTION_REMOVE:
asprintf(&filename, "%s/.remove", subdomainbase);
if (asprintf(&filename, "%s/.remove", subdomainbase) == -1)
goto exit;
fd = open(filename, O_WRONLY);
break;
case OPTION_STDOUT:
@ -820,6 +823,8 @@ int sd_serialize_codomain(int option, struct codomain *cod)
goto exit;
}
error = 0;
if (option != OPTION_STDOUT)
free(filename);
@ -938,17 +943,19 @@ static char *next_profile_buffer(char *buffer, int size)
int sd_load_buffer(int option, char *buffer, int size)
{
int fd;
int error = 0, wsize, bsize;
int error = -ENOMEM, wsize, bsize;
char *filename = NULL;
char *b;
switch (option) {
case OPTION_ADD:
asprintf(&filename, "%s/.load", subdomainbase);
if (asprintf(&filename, "%s/.load", subdomainbase) == -1)
goto exit;
fd = open(filename, O_WRONLY);
break;
case OPTION_REPLACE:
asprintf(&filename, "%s/.replace", subdomainbase);
if (asprintf(&filename, "%s/.replace", subdomainbase) == -1)
goto exit;
fd = open(filename, O_WRONLY);
break;
default:
@ -964,6 +971,7 @@ int sd_load_buffer(int option, char *buffer, int size)
goto exit;
}
error = 0;
for (b = buffer; b ; b = next_profile_buffer(b + sizeof(header_version), bsize)) {
bsize = size - (b - buffer);
wsize = write(fd, b, bsize);

View file

@ -152,10 +152,11 @@ static int expand_entry_variables(struct cod_entry *entry)
exit(1);
}
free(entry->name);
asprintf(&(entry->name), "%s%s%s",
split_var->prefix ? split_var->prefix : "",
value,
split_var->suffix ? split_var->suffix : "");
if (asprintf(&(entry->name), "%s%s%s",
split_var->prefix ? split_var->prefix : "",
value,
split_var->suffix ? split_var->suffix : "") == -1)
return FALSE;
while ((value = get_next_set_value(&valuelist))) {
struct cod_entry *dupe = copy_cod_entry(entry);
@ -167,10 +168,10 @@ static int expand_entry_variables(struct cod_entry *entry)
entry->next = dupe;
free(entry->name);
asprintf(&(entry->name), "%s%s%s",
split_var->prefix ? split_var->prefix : "",
value,
split_var->suffix ? split_var->suffix : "");
if (asprintf(&(entry->name), "%s%s%s",
split_var->prefix ? split_var->prefix : "", value,
split_var->suffix ? split_var->suffix : "") == -1)
return FALSE;
}
free_var_string(split_var);
@ -268,7 +269,7 @@ int test_split_string(void)
char *var = "boogie";
char *suffix = "suffixication";
asprintf(&tst_string, "%s@{%s}%s", prefix, var, suffix);
(void) asprintf(&tst_string, "%s@{%s}%s", prefix, var, suffix);
var_start = tst_string + strlen(prefix);
var_end = var_start + strlen(var) + strlen("@\{");
ret_struct = split_string(tst_string, var_start, var_end);