Skip to content

Commit

Permalink
Fix use of uninitialised variable
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Rodgman <[email protected]>
  • Loading branch information
daverodgman committed Mar 31, 2023
1 parent b2e3c7a commit 8f109fc
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions library/timing.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,7 @@ volatile int mbedtls_timing_alarmed = 0;

unsigned long mbedtls_timing_get_timer(struct mbedtls_timing_hr_time *val, int reset)
{
/* We can't safely cast val because it may not be aligned, so use memcpy */
struct _hr_time t;
memcpy(&t, val, sizeof(struct _hr_time));

if (reset) {
QueryPerformanceCounter(&t.start);
Expand All @@ -244,6 +242,8 @@ unsigned long mbedtls_timing_get_timer(struct mbedtls_timing_hr_time *val, int r
} else {
unsigned long delta;
LARGE_INTEGER now, hfreq;
/* We can't safely cast val because it may not be aligned, so use memcpy */
memcpy(&t, val, sizeof(struct _hr_time));
QueryPerformanceCounter(&now);
QueryPerformanceFrequency(&hfreq);
delta = (unsigned long) ((now.QuadPart - t.start.QuadPart) * 1000ul
Expand Down Expand Up @@ -282,9 +282,7 @@ void mbedtls_set_alarm(int seconds)

unsigned long mbedtls_timing_get_timer(struct mbedtls_timing_hr_time *val, int reset)
{
/* We can't safely cast val because it may not be aligned, so use memcpy */
struct _hr_time t;
memcpy(&t, val, sizeof(struct _hr_time));

if (reset) {
gettimeofday(&t.start, NULL);
Expand All @@ -293,6 +291,8 @@ unsigned long mbedtls_timing_get_timer(struct mbedtls_timing_hr_time *val, int r
} else {
unsigned long delta;
struct timeval now;
/* We can't safely cast val because it may not be aligned, so use memcpy */
memcpy(&t, val, sizeof(struct _hr_time));
gettimeofday(&now, NULL);
delta = (now.tv_sec - t.start.tv_sec) * 1000ul
+ (now.tv_usec - t.start.tv_usec) / 1000;
Expand Down

0 comments on commit 8f109fc

Please sign in to comment.