Commit 7417cb12 authored by Matthias Braun's avatar Matthias Braun
Browse files

strcalc: cleanup sc_inc, fix buffer not getting copied completely

parent 54ddf276
......@@ -119,19 +119,19 @@ void sc_andnot(const sc_word *val1, const sc_word *val2, sc_word *buffer)
*/
static void sc_inc(const sc_word *val, sc_word *buffer)
{
unsigned counter = 0;
while (counter++ < calc_buffer_size) {
if (*val == 15) {
*buffer++ = 0;
val++;
} else {
/* No carry here, *val != 15 */
*buffer = *val + 1;
return;
unsigned counter;
for (counter = 0; counter < calc_buffer_size; ++counter) {
sc_word v = val[counter];
if (v < SC_MASK) {
buffer[counter] = v+1;
/* copy the rest of the buffer if necessary */
if (buffer != val)
memcpy(&buffer[counter+1], &val[counter+1],
calc_buffer_size-(counter+1));
break;
}
buffer[counter] = 0;
}
/* here a carry could be lost, this is intended because this should
* happen only when a value changes sign. */
}
void sc_neg(const sc_word *val, sc_word *buffer)
......
......@@ -49,7 +49,7 @@ static bool is_zero(const sc_word *val)
int main(void)
{
init_strcalc(precision);
buflen = sc_get_buffer_length() + 1;
buflen = sc_get_buffer_length();
sc_word *temp = ALLOCAN(sc_word, buflen);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment