aboutsummaryrefslogtreecommitdiff
path: root/py/mpz.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-12-28 14:14:06 +1100
committerDamien George <damien.p.george@gmail.com>2017-12-29 14:17:55 +1100
commite78427443094163d1839387a2470fd22612ca8d1 (patch)
tree6acf62bf71c54169aa296eebf36f968bc434fbec /py/mpz.c
parent9766fddcdc29cb2b5a8657389b870703580a6e57 (diff)
py/mpz: In mpz_as_str_inpl, convert always-false checks to assertions.
There are two checks that are always false so can be converted to (negated) assertions to save code space and execution time. They are: 1. The check of the str parameter, which is required to be non-NULL as per the original comment that it has enough space in it as calculated by mp_int_format_size. And for all uses of this function str is indeed non-NULL. 2. The check of the base parameter, which is already required to be between 2 and 16 (inclusive) via the assertion in mp_int_format_size.
Diffstat (limited to 'py/mpz.c')
-rw-r--r--py/mpz.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/py/mpz.c b/py/mpz.c
index 78dee3132..380e8968e 100644
--- a/py/mpz.c
+++ b/py/mpz.c
@@ -1647,16 +1647,12 @@ char *mpz_as_str(const mpz_t *i, unsigned int base) {
}
#endif
-// assumes enough space as calculated by mp_int_format_size
+// assumes enough space in str as calculated by mp_int_format_size
+// base must be between 2 and 32 inclusive
// returns length of string, not including null byte
size_t mpz_as_str_inpl(const mpz_t *i, unsigned int base, const char *prefix, char base_char, char comma, char *str) {
- if (str == NULL) {
- return 0;
- }
- if (base < 2 || base > 32) {
- str[0] = 0;
- return 0;
- }
+ assert(str != NULL);
+ assert(2 <= base && base <= 32);
size_t ilen = i->len;