Skip to content

Commit

Permalink
Fix a couple NULL pointer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
RH-steve-grubb committed Feb 9, 2023
1 parent ee9c99a commit 3592df9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/library/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ char *bytes2hex(char *final, const unsigned char *buf, unsigned int size)
char *ptr = final;
const char *hex = "0123456789abcdef";

if (final == NULL)
return final;

for (i=0; i<size; i++) {
*ptr++ = hex[(buf[i] & 0xF0)>>4]; /* Upper nibble */
*ptr++ = hex[buf[i] & 0x0F]; /* Lower nibble */
Expand Down Expand Up @@ -488,6 +491,9 @@ static Elf32_Ehdr *read_header32(int fd) MALLOCLIKE;
static Elf32_Ehdr *read_header32(int fd)
{
Elf32_Ehdr *ptr = malloc(sizeof(Elf32_Ehdr));
if (ptr == NULL)
return NULL;

memcpy(ptr->e_ident, e_ident, EI_NIDENT);
ssize_t rc = safe_read(fd, (char *)ptr + EI_NIDENT,
sizeof(Elf32_Ehdr) - EI_NIDENT);
Expand All @@ -502,6 +508,9 @@ static Elf64_Ehdr *read_header64(int fd) MALLOCLIKE;
static Elf64_Ehdr *read_header64(int fd)
{
Elf64_Ehdr *ptr = malloc(sizeof(Elf64_Ehdr));
if (ptr == NULL)
return NULL;

memcpy(ptr->e_ident, e_ident, EI_NIDENT);
ssize_t rc = safe_read(fd, (char *)ptr + EI_NIDENT,
sizeof(Elf64_Ehdr) - EI_NIDENT);
Expand Down
2 changes: 2 additions & 0 deletions src/tests/avl_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ static int intcmp_cb(void *a, void *b)
int append(int num)
{
avl_int_data_t *data = malloc(sizeof(avl_int_data_t));
if (data == NULL)
return 0;
data->num = num;
avl_t *ret = avl_insert(&tree, (avl_t *)data);
if (ret != (avl_t *)data) {
Expand Down

0 comments on commit 3592df9

Please sign in to comment.