Commit 8997116e by Marcus Winter

base_c: fixed uninitialized variables in failure cases

parent 5eec1ace
...@@ -49,10 +49,14 @@ int embb_duration_set_nanoseconds(embb_duration_t* duration, ...@@ -49,10 +49,14 @@ int embb_duration_set_nanoseconds(embb_duration_t* duration,
assert(duration != NULL); assert(duration != NULL);
if (nanoseconds > 0) { if (nanoseconds > 0) {
if (embb_duration_min()->nanoseconds > nanoseconds) { if (embb_duration_min()->nanoseconds > nanoseconds) {
duration->seconds = 0;
duration->nanoseconds = 0;
return EMBB_UNDERFLOW; return EMBB_UNDERFLOW;
} }
const embb_duration_t* max = embb_duration_max(); const embb_duration_t* max = embb_duration_max();
if (max->seconds * 1000000000 + max->nanoseconds < nanoseconds) { if (max->seconds * 1000000000 + max->nanoseconds < nanoseconds) {
duration->seconds = max->seconds;
duration->nanoseconds = max->nanoseconds;
return EMBB_OVERFLOW; return EMBB_OVERFLOW;
} }
} }
...@@ -66,10 +70,14 @@ int embb_duration_set_microseconds(embb_duration_t* duration, ...@@ -66,10 +70,14 @@ int embb_duration_set_microseconds(embb_duration_t* duration,
assert(duration != NULL); assert(duration != NULL);
if (microseconds > 0) { if (microseconds > 0) {
if (embb_duration_min()->nanoseconds > microseconds*1000) { if (embb_duration_min()->nanoseconds > microseconds*1000) {
duration->seconds = 0;
duration->nanoseconds = 0;
return EMBB_UNDERFLOW; return EMBB_UNDERFLOW;
} }
const embb_duration_t* max = embb_duration_max(); const embb_duration_t* max = embb_duration_max();
if (max->seconds * 1000000 + max->nanoseconds / 1000 < microseconds) { if (max->seconds * 1000000 + max->nanoseconds / 1000 < microseconds) {
duration->seconds = max->seconds;
duration->nanoseconds = max->nanoseconds;
return EMBB_OVERFLOW; return EMBB_OVERFLOW;
} }
} }
...@@ -83,10 +91,14 @@ int embb_duration_set_milliseconds(embb_duration_t* duration, ...@@ -83,10 +91,14 @@ int embb_duration_set_milliseconds(embb_duration_t* duration,
assert(duration != NULL); assert(duration != NULL);
if (milliseconds > 0) { if (milliseconds > 0) {
if (embb_duration_min()->nanoseconds > milliseconds*1000000) { if (embb_duration_min()->nanoseconds > milliseconds*1000000) {
duration->seconds = 0;
duration->nanoseconds = 0;
return EMBB_UNDERFLOW; return EMBB_UNDERFLOW;
} }
const embb_duration_t* max = embb_duration_max(); const embb_duration_t* max = embb_duration_max();
if (max->seconds * 1000 + max->nanoseconds / 1000000 < milliseconds) { if (max->seconds * 1000 + max->nanoseconds / 1000000 < milliseconds) {
duration->seconds = max->seconds;
duration->nanoseconds = max->nanoseconds;
return EMBB_OVERFLOW; return EMBB_OVERFLOW;
} }
} }
...@@ -100,10 +112,14 @@ int embb_duration_set_seconds(embb_duration_t* duration, ...@@ -100,10 +112,14 @@ int embb_duration_set_seconds(embb_duration_t* duration,
assert(duration != NULL); assert(duration != NULL);
if (seconds > 0) { if (seconds > 0) {
if (embb_duration_min()->nanoseconds > seconds*1000000000) { if (embb_duration_min()->nanoseconds > seconds*1000000000) {
duration->seconds = 0;
duration->nanoseconds = 0;
return EMBB_UNDERFLOW; return EMBB_UNDERFLOW;
} }
const embb_duration_t* max = embb_duration_max(); const embb_duration_t* max = embb_duration_max();
if (max->seconds + max->nanoseconds / 1000000000 < seconds) { if (max->seconds + max->nanoseconds / 1000000000 < seconds) {
duration->seconds = max->seconds;
duration->nanoseconds = max->nanoseconds;
return EMBB_OVERFLOW; return EMBB_OVERFLOW;
} }
} }
...@@ -117,6 +133,8 @@ int embb_duration_add(embb_duration_t* lhs, const embb_duration_t* rhs) { ...@@ -117,6 +133,8 @@ int embb_duration_add(embb_duration_t* lhs, const embb_duration_t* rhs) {
assert(rhs != NULL); assert(rhs != NULL);
int carry = (int)((lhs->nanoseconds + rhs->nanoseconds) / 1000000000); int carry = (int)((lhs->nanoseconds + rhs->nanoseconds) / 1000000000);
if (lhs->seconds + rhs->seconds + carry > EMBB_DURATION_MAX_SECONDS) { if (lhs->seconds + rhs->seconds + carry > EMBB_DURATION_MAX_SECONDS) {
lhs->seconds = 0;
lhs->nanoseconds = 0;
return EMBB_OVERFLOW; return EMBB_OVERFLOW;
} }
lhs->nanoseconds = (lhs->nanoseconds + rhs->nanoseconds) % 1000000000; lhs->nanoseconds = (lhs->nanoseconds + rhs->nanoseconds) % 1000000000;
......
...@@ -83,7 +83,10 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set, ...@@ -83,7 +83,10 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
assert(thread != NULL); assert(thread != NULL);
thread->embb_internal_arg = (embb_internal_thread_arg_t*) thread->embb_internal_arg = (embb_internal_thread_arg_t*)
embb_alloc(sizeof(embb_internal_thread_arg_t)); embb_alloc(sizeof(embb_internal_thread_arg_t));
if (thread->embb_internal_arg == NULL) return EMBB_NOMEM; if (thread->embb_internal_arg == NULL) {
thread->embb_internal_handle = NULL;
return EMBB_NOMEM;
}
thread->embb_internal_arg->func = func; thread->embb_internal_arg->func = func;
thread->embb_internal_arg->arg = arg; thread->embb_internal_arg->arg = arg;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment