libsepol: do not create a string list with initial size zero
Currently is it implementation defined, due to the size being passed to calloc(3), whether the operations fails nor not. Also strs_add() does not handle a size of zero, cause it just multiplies the size by two. Use a default size of 1 if 0 is passed and swap the calloc arguments for consistency. Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
This commit is contained in:
parent
35ef9b95e7
commit
691e6aff4c
1 changed files with 5 additions and 1 deletions
|
@ -107,6 +107,10 @@ int strs_init(struct strs **strs, size_t size)
|
|||
{
|
||||
struct strs *new;
|
||||
|
||||
if (size == 0) {
|
||||
size = 1;
|
||||
}
|
||||
|
||||
*strs = NULL;
|
||||
|
||||
new = malloc(sizeof(struct strs));
|
||||
|
@ -115,7 +119,7 @@ int strs_init(struct strs **strs, size_t size)
|
|||
return -1;
|
||||
}
|
||||
|
||||
new->list = calloc(sizeof(char *), size);
|
||||
new->list = calloc(size, sizeof(char *));
|
||||
if (!new->list) {
|
||||
sepol_log_err("Out of memory");
|
||||
free(new);
|
||||
|
|
Loading…
Reference in a new issue