ensure realloc has a positive size
If given size 0 POSIX allows realloc to return a pointer that is not suitable for use. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
0fd6d354a6
commit
6eac7258cd
2 changed files with 14 additions and 6 deletions
|
@ -810,9 +810,13 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
|
|||
files_count++;
|
||||
}
|
||||
/* attempt to hand back any memory we don't need */
|
||||
if(files_count > 0) {
|
||||
files = realloc(files, sizeof(alpm_file_t) * files_count);
|
||||
/* make sure the list is sorted */
|
||||
qsort(files, files_count, sizeof(alpm_file_t), _alpm_files_cmp);
|
||||
} else {
|
||||
FREE(files);
|
||||
}
|
||||
info->files.count = files_count;
|
||||
info->files.files = files;
|
||||
} else if(strcmp(line, "%BACKUP%") == 0) {
|
||||
|
|
|
@ -721,9 +721,13 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
|
|||
files_count++;
|
||||
}
|
||||
/* attempt to hand back any memory we don't need */
|
||||
if(files_count > 0) {
|
||||
files = realloc(files, sizeof(alpm_file_t) * files_count);
|
||||
/* make sure the list is sorted */
|
||||
qsort(files, files_count, sizeof(alpm_file_t), _alpm_files_cmp);
|
||||
} else {
|
||||
FREE(files);
|
||||
}
|
||||
pkg->files.count = files_count;
|
||||
pkg->files.files = files;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue