summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkennykb <kennykb@noemail.net>2005-05-10 17:20:39 (GMT)
committerkennykb <kennykb@noemail.net>2005-05-10 17:20:39 (GMT)
commitb4e4f618035fce9c41fdbdb94a781e6e33d02427 (patch)
tree2a8c6a5370bc1ab79e9ed6d477146fe18604eb59
parenta7e7e9d3870a6ffc42a68b10ee6698f8ba65c21c (diff)
downloadtcl-b4e4f618035fce9c41fdbdb94a781e6e33d02427.zip
tcl-b4e4f618035fce9c41fdbdb94a781e6e33d02427.tar.gz
tcl-b4e4f618035fce9c41fdbdb94a781e6e33d02427.tar.bz2
committed local libtommath changes from kennykb-numerics-branch back to the Tcl HEAD
FossilOrigin-Name: edc85b6177d417c7474a8ddd6556f8d136536a27
-rw-r--r--libtommath/bn_mp_radix_size.c13
-rw-r--r--libtommath/bn_mp_read_radix.c7
-rw-r--r--libtommath/tommath.h2
3 files changed, 19 insertions, 3 deletions
diff --git a/libtommath/bn_mp_radix_size.c b/libtommath/bn_mp_radix_size.c
index 3d423ba..29b1d22 100644
--- a/libtommath/bn_mp_radix_size.c
+++ b/libtommath/bn_mp_radix_size.c
@@ -66,8 +66,17 @@ int mp_radix_size (mp_int * a, int radix, int *size)
}
mp_clear (&t);
- /* return digs + 1, the 1 is for the NULL byte that would be required. */
- *size = digs + 1;
+ /*
+ * return digs + 1, the 1 is for the NULL byte that would be required.
+ * mp_toradix_n requires a minimum of 3 bytes, so never report less than
+ * that.
+ */
+
+ if ( digs >= 2 ) {
+ *size = digs + 1;
+ } else {
+ *size = 3;
+ }
return MP_OKAY;
}
diff --git a/libtommath/bn_mp_read_radix.c b/libtommath/bn_mp_read_radix.c
index 1ec3937..1e272fb 100644
--- a/libtommath/bn_mp_read_radix.c
+++ b/libtommath/bn_mp_read_radix.c
@@ -69,6 +69,13 @@ int mp_read_radix (mp_int * a, const char *str, int radix)
++str;
}
+ /* if an illegal character was found, fail. */
+
+ if ( *str != '\0' ) {
+ mp_zero( a );
+ return MP_VAL;
+ }
+
/* set the sign only if a != 0 */
if (mp_iszero(a) != 1) {
a->sign = neg;
diff --git a/libtommath/tommath.h b/libtommath/tommath.h
index bcb9d86..ce8591f 100644
--- a/libtommath/tommath.h
+++ b/libtommath/tommath.h
@@ -217,7 +217,7 @@ int mp_init_size(mp_int *a, int size);
/* ---> Basic Manipulations <--- */
#define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
-#define mp_iseven(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO)
+#define mp_iseven(a) (((a)->used == 0 || (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO)
#define mp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO)
/* set to zero */