Skip to content

Commit 5d22ca6

Browse files
committed
Fix #688, update all OSAL argument checks
Use the new macros to validate arguments to OS API calls. Also includes coverage test updates, which revealed some areas where return types were not consistent, and the macro makes them consistent now.
1 parent f9e9b28 commit 5d22ca6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+295
-565
lines changed

src/os/shared/src/osapi-binsem.c

+8-19
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,9 @@ int32 OS_BinSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initia
100100
OS_object_token_t token;
101101
OS_bin_sem_internal_record_t *binsem;
102102

103-
/* Check for NULL pointers */
104-
if (sem_id == NULL || sem_name == NULL)
105-
{
106-
return OS_INVALID_POINTER;
107-
}
108-
109-
if (strlen(sem_name) >= OS_MAX_API_NAME)
110-
{
111-
return OS_ERR_NAME_TOO_LONG;
112-
}
103+
/* Check inputs */
104+
OS_CHECK_POINTER(sem_id);
105+
OS_CHECK_APINAME(sem_name);
113106

114107
/* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */
115108
return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, sem_name, &token);
@@ -262,10 +255,9 @@ int32 OS_BinSemGetIdByName(osal_id_t *sem_id, const char *sem_name)
262255
{
263256
int32 return_code;
264257

265-
if (sem_id == NULL || sem_name == NULL)
266-
{
267-
return OS_INVALID_POINTER;
268-
}
258+
/* Check inputs */
259+
OS_CHECK_POINTER(sem_id);
260+
OS_CHECK_POINTER(sem_name);
269261

270262
return_code = OS_ObjectIdFindByName(LOCAL_OBJID_TYPE, sem_name, sem_id);
271263

@@ -286,11 +278,8 @@ int32 OS_BinSemGetInfo(osal_id_t sem_id, OS_bin_sem_prop_t *bin_prop)
286278
OS_object_token_t token;
287279
int32 return_code;
288280

289-
/* Check parameters */
290-
if (bin_prop == NULL)
291-
{
292-
return OS_INVALID_POINTER;
293-
}
281+
/* Check inputs */
282+
OS_CHECK_POINTER(bin_prop);
294283

295284
memset(bin_prop, 0, sizeof(OS_bin_sem_prop_t));
296285

src/os/shared/src/osapi-clock.c

+4-8
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,8 @@
5050
*-----------------------------------------------------------------*/
5151
int32 OS_GetLocalTime(OS_time_t *time_struct)
5252
{
53-
if (time_struct == NULL)
54-
{
55-
return OS_INVALID_POINTER;
56-
}
53+
/* Check inputs */
54+
OS_CHECK_POINTER(time_struct);
5755

5856
return OS_GetLocalTime_Impl(time_struct);
5957

@@ -69,10 +67,8 @@ int32 OS_GetLocalTime(OS_time_t *time_struct)
6967
*-----------------------------------------------------------------*/
7068
int32 OS_SetLocalTime(OS_time_t *time_struct)
7169
{
72-
if (time_struct == NULL)
73-
{
74-
return OS_INVALID_POINTER;
75-
}
70+
/* Check inputs */
71+
OS_CHECK_POINTER(time_struct);
7672

7773
return OS_SetLocalTime_Impl(time_struct);
7874

src/os/shared/src/osapi-common.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,7 @@ int32 OS_API_Init(void)
229229
*-----------------------------------------------------------------*/
230230
int32 OS_RegisterEventHandler(OS_EventHandler_t handler)
231231
{
232-
if (handler == NULL)
233-
{
234-
return OS_INVALID_POINTER;
235-
}
232+
OS_CHECK_POINTER(handler);
236233

237234
OS_SharedGlobalVars.EventHandler = handler;
238235
return OS_SUCCESS;

src/os/shared/src/osapi-countsem.c

+8-19
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,9 @@ int32 OS_CountSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_init
9292
OS_object_token_t token;
9393
OS_count_sem_internal_record_t *countsem;
9494

95-
/* Check for NULL pointers */
96-
if (sem_id == NULL || sem_name == NULL)
97-
{
98-
return OS_INVALID_POINTER;
99-
}
100-
101-
if (strlen(sem_name) >= OS_MAX_API_NAME)
102-
{
103-
return OS_ERR_NAME_TOO_LONG;
104-
}
95+
/* Check inputs */
96+
OS_CHECK_POINTER(sem_id);
97+
OS_CHECK_APINAME(sem_name);
10598

10699
/* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */
107100
return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, sem_name, &token);
@@ -231,10 +224,9 @@ int32 OS_CountSemGetIdByName(osal_id_t *sem_id, const char *sem_name)
231224
{
232225
int32 return_code;
233226

234-
if (sem_id == NULL || sem_name == NULL)
235-
{
236-
return OS_INVALID_POINTER;
237-
}
227+
/* Check inputs */
228+
OS_CHECK_POINTER(sem_id);
229+
OS_CHECK_POINTER(sem_name);
238230

239231
return_code = OS_ObjectIdFindByName(LOCAL_OBJID_TYPE, sem_name, sem_id);
240232

@@ -255,11 +247,8 @@ int32 OS_CountSemGetInfo(osal_id_t sem_id, OS_count_sem_prop_t *count_prop)
255247
OS_object_token_t token;
256248
int32 return_code;
257249

258-
/* Check parameters */
259-
if (count_prop == NULL)
260-
{
261-
return OS_INVALID_POINTER;
262-
}
250+
/* Check inputs */
251+
OS_CHECK_POINTER(count_prop);
263252

264253
memset(count_prop, 0, sizeof(OS_count_sem_prop_t));
265254

src/os/shared/src/osapi-dir.c

+4-8
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,8 @@ int32 OS_DirectoryOpen(osal_id_t *dir_id, const char *path)
118118
OS_dir_internal_record_t *dir;
119119
int32 return_code;
120120

121-
if (dir_id == NULL || path == NULL)
122-
{
123-
return OS_INVALID_POINTER;
124-
}
121+
/* Check inputs */
122+
OS_CHECK_POINTER(dir_id);
125123

126124
return_code = OS_TranslatePath(path, local_path);
127125
if (return_code == OS_SUCCESS)
@@ -185,10 +183,8 @@ int32 OS_DirectoryRead(osal_id_t dir_id, os_dirent_t *dirent)
185183
OS_object_token_t token;
186184
int32 return_code;
187185

188-
if (dirent == NULL)
189-
{
190-
return OS_INVALID_POINTER;
191-
}
186+
/* Check inputs */
187+
OS_CHECK_POINTER(dirent);
192188

193189
/* Make sure the file descriptor is legit before using it */
194190
return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, dir_id, &token);

src/os/shared/src/osapi-errors.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,7 @@ int32 OS_GetErrorName(int32 error_num, os_err_name_t *err_name)
101101
uint32 return_code;
102102
const OS_ErrorTable_Entry_t *Error;
103103

104-
if (err_name == NULL)
105-
{
106-
return OS_INVALID_POINTER;
107-
}
104+
OS_CHECK_POINTER(err_name);
108105

109106
Error = OS_GLOBAL_ERROR_NAME_TABLE;
110107
while (Error->Name != NULL && Error->Number != error_num)

src/os/shared/src/osapi-file.c

+13-32
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 acc
102102
OS_object_token_t token;
103103
OS_stream_internal_record_t *stream;
104104

105-
if (filedes == NULL)
106-
{
107-
return OS_INVALID_POINTER;
108-
}
105+
OS_CHECK_POINTER(filedes);
109106

110107
/*
111108
** Check for a valid access mode
@@ -266,10 +263,8 @@ int32 OS_TimedRead(osal_id_t filedes, void *buffer, size_t nbytes, int32 timeout
266263
int32 return_code;
267264

268265
/* Check Parameters */
269-
if (buffer == NULL || nbytes == 0)
270-
{
271-
return OS_INVALID_POINTER;
272-
}
266+
OS_CHECK_POINTER(buffer);
267+
OS_CHECK_SIZE(nbytes);
273268

274269
return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &token);
275270
if (return_code == OS_SUCCESS)
@@ -296,10 +291,8 @@ int32 OS_TimedWrite(osal_id_t filedes, const void *buffer, size_t nbytes, int32
296291
int32 return_code;
297292

298293
/* Check Parameters */
299-
if (buffer == NULL || nbytes == 0)
300-
{
301-
return OS_INVALID_POINTER;
302-
}
294+
OS_CHECK_POINTER(buffer);
295+
OS_CHECK_SIZE(nbytes);
303296

304297
return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &token);
305298
if (return_code == OS_SUCCESS)
@@ -373,10 +366,8 @@ int32 OS_stat(const char *path, os_fstat_t *filestats)
373366
int32 return_code;
374367
char local_path[OS_MAX_LOCAL_PATH_LEN];
375368

376-
if (filestats == NULL)
377-
{
378-
return OS_INVALID_POINTER;
379-
}
369+
/* Check Parameters */
370+
OS_CHECK_POINTER(filestats);
380371

381372
memset(filestats, 0, sizeof(*filestats));
382373

@@ -502,10 +493,9 @@ int32 OS_cp(const char *src, const char *dest)
502493
osal_id_t file2;
503494
uint8 copyblock[512];
504495

505-
if (src == NULL || dest == NULL)
506-
{
507-
return OS_INVALID_POINTER;
508-
}
496+
/* Check Parameters */
497+
OS_CHECK_POINTER(src);
498+
OS_CHECK_POINTER(dest);
509499

510500
file1 = OS_OBJECT_ID_UNDEFINED;
511501
file2 = OS_OBJECT_ID_UNDEFINED;
@@ -595,10 +585,7 @@ int32 OS_FDGetInfo(osal_id_t filedes, OS_file_prop_t *fd_prop)
595585
int32 return_code;
596586

597587
/* Check parameters */
598-
if (fd_prop == NULL)
599-
{
600-
return (OS_INVALID_POINTER);
601-
}
588+
OS_CHECK_POINTER(fd_prop);
602589

603590
memset(fd_prop, 0, sizeof(OS_file_prop_t));
604591

@@ -633,10 +620,7 @@ int32 OS_FileOpenCheck(const char *Filename)
633620
OS_object_iter_t iter;
634621
OS_stream_internal_record_t *stream;
635622

636-
if (Filename == NULL)
637-
{
638-
return (OS_INVALID_POINTER);
639-
}
623+
OS_CHECK_POINTER(Filename);
640624

641625
return_code = OS_ERROR;
642626

@@ -672,10 +656,7 @@ int32 OS_CloseFileByName(const char *Filename)
672656
OS_object_iter_t iter;
673657
OS_stream_internal_record_t *stream;
674658

675-
if (Filename == NULL)
676-
{
677-
return (OS_INVALID_POINTER);
678-
}
659+
OS_CHECK_POINTER(Filename);
679660

680661
return_code = OS_FS_ERR_PATH_INVALID;
681662

0 commit comments

Comments
 (0)