Skip to content

Commit cfe0a5d

Browse files
author
Kevin Moloney
committed
Fix Klocwork#105: Pointer returned may be null.
* Added a check for this null pointer. Signed-off-by: Kevin Moloney <[email protected]>
1 parent 5e71e70 commit cfe0a5d

File tree

1 file changed

+7
-4
lines changed
  • system/libarc32_arduino101/framework/src/os

1 file changed

+7
-4
lines changed

system/libarc32_arduino101/framework/src/os/os.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ 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+
return 0;
5053
}
5154

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

0 commit comments

Comments
 (0)