Skip to content

Commit c7ad493

Browse files
szsammysterywolf
authored andcommitted
[libc][ctime] move null pointer check before dereference
This null check was redundant because the pointer timep was dereferenced in any case.
1 parent 6198eea commit c7ad493

File tree

1 file changed

+2
-1
lines changed
  • components/libc/compilers/common

1 file changed

+2
-1
lines changed

components/libc/compilers/common/ctime.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static int set_timeval(struct timeval *tv)
177177
struct tm *gmtime_r(const time_t *timep, struct tm *r)
178178
{
179179
int i;
180-
int work = *timep % (SPD);
180+
int work;
181181

182182
if(timep == RT_NULL || r == RT_NULL)
183183
{
@@ -187,6 +187,7 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r)
187187

188188
rt_memset(r, RT_NULL, sizeof(struct tm));
189189

190+
work = *timep % (SPD);
190191
r->tm_sec = work % 60;
191192
work /= 60;
192193
r->tm_min = work % 60;

0 commit comments

Comments
 (0)