diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-03-04 23:50:00 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-03-04 23:50:00 +0100 |
| commit | 76d0af5599554d11f104d582cdac8fbaa8569fcc (patch) | |
| tree | 0ed9889a86d52ebd208382f2fd49dad0570d1f8c /src/zrsh.c | |
| parent | Clean up, fix a few bugs, and add a test (diff) | |
| download | libzahl-76d0af5599554d11f104d582cdac8fbaa8569fcc.tar.gz libzahl-76d0af5599554d11f104d582cdac8fbaa8569fcc.tar.bz2 libzahl-76d0af5599554d11f104d582cdac8fbaa8569fcc.tar.xz | |
Clean up, add zerror and zperror, fix bugs and add more tests
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/zrsh.c')
| -rw-r--r-- | src/zrsh.c | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -20,7 +20,7 @@ zrsh(z_t a, z_t b, size_t bits) } bits = BITS_IN_LAST_CHAR(bits); - cbits = BITS_PER_CHAR - 1 - bits; + cbits = BITS_PER_CHAR - bits; if (chars && a == b) { a->used -= chars; @@ -31,10 +31,14 @@ zrsh(z_t a, z_t b, size_t bits) zmemcpy(a->chars, b->chars + chars, a->used); } - a->chars[0] >>= bits; - for (i = 1; i < a->used; i++) { - a->chars[i - 1] |= a->chars[i] >> cbits; - a->chars[i] >>= bits; + if (bits) { /* This if statement is very important in C. */ + a->chars[0] >>= bits; + for (i = 1; i < a->used; i++) { + a->chars[i - 1] |= a->chars[i] << cbits; + a->chars[i] >>= bits; + } + while (!a->chars[a->used - 1]) + a->used--; } SET_SIGNUM(a, zsignum(b)); |
