Skip to content

Commit 5a1c28c

Browse files
author
Kevin Moloney
committed
ATLEDGE 201 Pointer returned may be null
Added a check for this null pointer. Signed-off-by: Kevin Moloney <kevin.moloney@emutex.com>
1 parent 45e6046 commit 5a1c28c

File tree

1 file changed

+9
-4
lines changed
  • system/libarc32_edu/framework/src/os

1 file changed

+9
-4
lines changed

system/libarc32_edu/framework/src/os/os.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ void * cfw_alloc(int size, OS_ERR_TYPE * err) {
4141
void * ptr;
4242
unsigned int flags = interrupt_lock();
4343
ptr = malloc(size+sizeof(void*));
44-
(*(int*) ptr) = size;
44+
if (ptr != NULL) {
45+
(*(int*) ptr) = size;
4546
#ifdef TRACK_ALLOCS
46-
alloc_count++;
47+
alloc_count++;
4748
#endif
48-
interrupt_unlock(flags);
49-
return ptr;
49+
interrupt_unlock(flags);
50+
return ptr;
51+
} else {
52+
interrupt_unlock(flags);
53+
return 0;
54+
}
5055
}
5156

5257
void cfw_free(void * ptr, OS_ERR_TYPE * err) {

0 commit comments

Comments
 (0)