compat/freebsd_network: Fix Use of zero-allocated memory

If device is not found, 'list' is allocated to size 0.
So, modify function to return 0 as FreeBSD's subr_bus.c
when 'count' is 0.
Pointed out by Clang Static Analyzer.

Change-Id: Ice24ae939bfcdb6e1276a86dba40d0b689030fbb
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3753
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
Murai Takashi 2021-02-25 20:30:14 +09:00 committed by Adrien Destugues
parent 761714b3f6
commit 8cd3603b99

View File

@ -198,6 +198,12 @@ device_get_children(device_t dev, device_t **devlistp, int *devcountp)
count++;
}
if (count == 0) {
*devlistp = NULL;
*devcountp = 0;
return (0);
}
list = malloc(count * sizeof(device_t));
if (!list)
return (ENOMEM);