logger: exit with error if calloc fails

In user-space tools, memory allocations can reasonably be expected to
always succeed. Make this assumption explicit by adding error handling
after calloc.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
This commit is contained in:
Kai Vehmanen 2022-12-19 16:41:48 +02:00 committed by Kai Vehmanen
parent 4d64893b86
commit 4bec5b292c
1 changed files with 4 additions and 0 deletions

View File

@ -131,6 +131,10 @@ static const char *format_uid(uint32_t uid_ptr, int use_colors, bool be, bool up
if (uid_ptr < uids_dict->base_address || if (uid_ptr < uids_dict->base_address ||
uid_ptr >= uids_dict->base_address + uids_dict->data_length) { uid_ptr >= uids_dict->base_address + uids_dict->data_length) {
str = calloc(1, strlen(BAD_PTR_STR) + 1 + 6); str = calloc(1, strlen(BAD_PTR_STR) + 1 + 6);
if (!str) {
log_err("can't allocate memory\n");
exit(EXIT_FAILURE);
}
sprintf(str, BAD_PTR_STR, uid_ptr); sprintf(str, BAD_PTR_STR, uid_ptr);
} else { } else {
uid_entry = get_uuid_entry(uid_ptr); uid_entry = get_uuid_entry(uid_ptr);