mirror of
https://github.com/yuzu-emu/mbedtls
synced 2024-11-24 19:48:20 +00:00
timing.c: avoid referencing garbage value
Found with Clang's `scan-build` tool. When get_timer() is called with `reset` set to 1, the value of t->start.tv_sec is used as a rvalue without being initialized first. This is relatively harmless because the result of get_timer() is not used by the callers when called in "reset mode". However, scan-build prints a warning. Silence the warning by only calculating the delta on non-reset runs, returning zero otherwise.
This commit is contained in:
parent
7ee55624fb
commit
b308dd72d9
1 changed files with 4 additions and 3 deletions
|
@ -283,15 +283,16 @@ unsigned long get_timer( struct hr_time *val, int reset )
|
||||||
|
|
||||||
gettimeofday( &offset, NULL );
|
gettimeofday( &offset, NULL );
|
||||||
|
|
||||||
delta = ( offset.tv_sec - t->start.tv_sec ) * 1000
|
|
||||||
+ ( offset.tv_usec - t->start.tv_usec ) / 1000;
|
|
||||||
|
|
||||||
if( reset )
|
if( reset )
|
||||||
{
|
{
|
||||||
t->start.tv_sec = offset.tv_sec;
|
t->start.tv_sec = offset.tv_sec;
|
||||||
t->start.tv_usec = offset.tv_usec;
|
t->start.tv_usec = offset.tv_usec;
|
||||||
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delta = ( offset.tv_sec - t->start.tv_sec ) * 1000
|
||||||
|
+ ( offset.tv_usec - t->start.tv_usec ) / 1000;
|
||||||
|
|
||||||
return( delta );
|
return( delta );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue