summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.fossil-settings/ignore-glob8
-rw-r--r--doc/format.n5
-rw-r--r--generic/tclStringObj.c27
-rw-r--r--generic/tclTomMath.h10
-rw-r--r--libtommath/bn_mp_2expt.c3
-rw-r--r--libtommath/bn_mp_abs.c3
-rw-r--r--libtommath/bn_mp_add_d.c3
-rw-r--r--libtommath/bn_mp_addmod.c3
-rw-r--r--libtommath/bn_mp_and.c3
-rw-r--r--libtommath/bn_mp_clamp.c3
-rw-r--r--libtommath/bn_mp_clear.c3
-rw-r--r--libtommath/bn_mp_cmp.c3
-rw-r--r--libtommath/bn_mp_copy.c3
-rw-r--r--libtommath/bn_mp_count_bits.c3
-rw-r--r--libtommath/bn_mp_div.c2
-rw-r--r--libtommath/bn_mp_div_3.c3
-rw-r--r--libtommath/bn_mp_div_d.c24
-rw-r--r--libtommath/bn_mp_dr_reduce.c3
-rw-r--r--libtommath/bn_mp_dr_setup.c3
-rw-r--r--libtommath/bn_mp_exch.c3
-rw-r--r--libtommath/bn_mp_export.c10
-rw-r--r--libtommath/bn_mp_exptmod_fast.c4
-rw-r--r--libtommath/bn_mp_exteuclid.c2
-rw-r--r--libtommath/bn_mp_get_int.c6
-rw-r--r--libtommath/bn_mp_get_long.c6
-rw-r--r--libtommath/bn_mp_get_long_long.c6
-rw-r--r--libtommath/bn_mp_import.c11
-rw-r--r--libtommath/bn_mp_is_square.c16
-rw-r--r--libtommath/bn_mp_mod.c3
-rw-r--r--libtommath/bn_mp_mod_2d.c3
-rw-r--r--libtommath/bn_mp_mod_d.c3
-rw-r--r--libtommath/bn_mp_montgomery_reduce.c3
-rw-r--r--libtommath/bn_mp_montgomery_setup.c3
-rw-r--r--libtommath/bn_mp_mul.c2
-rw-r--r--libtommath/bn_mp_mul_d.c7
-rw-r--r--libtommath/bn_mp_radix_size.c2
-rw-r--r--libtommath/bn_mp_rand.c3
-rw-r--r--libtommath/bn_mp_read_radix.c4
-rw-r--r--libtommath/bn_mp_reduce.c2
-rw-r--r--libtommath/bn_mp_reduce_2k_l.c2
-rw-r--r--libtommath/bn_mp_sqr.c3
-rw-r--r--libtommath/bn_mp_sqrmod.c3
-rw-r--r--libtommath/bn_mp_sub.c3
-rw-r--r--libtommath/bn_mp_sub_d.c3
-rw-r--r--libtommath/bn_mp_submod.c3
-rw-r--r--libtommath/bn_mp_toom_sqr.c3
-rw-r--r--libtommath/bn_mp_toradix.c2
-rw-r--r--libtommath/bn_mp_toradix_n.c2
-rw-r--r--libtommath/bn_mp_xor.c3
-rw-r--r--libtommath/bn_reverse.c3
-rw-r--r--libtommath/bn_s_mp_add.c3
-rw-r--r--libtommath/bn_s_mp_exptmod.c8
-rw-r--r--libtommath/bn_s_mp_mul_high_digs.c3
-rw-r--r--libtommath/bn_s_mp_sqr.c4
-rw-r--r--libtommath/bn_s_mp_sub.c3
-rw-r--r--libtommath/tommath.h10
-rw-r--r--tests/format.test18
-rw-r--r--tests/io.test2
-rw-r--r--win/nmakehlp.c10
-rw-r--r--win/tclWinFCmd.c4
-rw-r--r--win/tclWinLoad.c30
61 files changed, 167 insertions, 172 deletions
diff --git a/.fossil-settings/ignore-glob b/.fossil-settings/ignore-glob
index 08d388d..c85b488 100644
--- a/.fossil-settings/ignore-glob
+++ b/.fossil-settings/ignore-glob
@@ -18,6 +18,7 @@
*/tclsh*
*/tcltest*
*/versions.vc
+*/version.vc
html
libtommath/bn.ilg
libtommath/bn.ind
@@ -40,7 +41,8 @@ unix/dltest.marker
unix/tcl.pc
unix/tclIndex
unix/pkgs/*
-win/Debug_VC*
-win/Release_VC*
+win/Debug*
+win/Release*
win/pkgs/*
-win/tcl.hpj \ No newline at end of file
+win/tcl.hpj
+win/nmhlp-out.txt
diff --git a/doc/format.n b/doc/format.n
index 4eb566d..1df255e 100644
--- a/doc/format.n
+++ b/doc/format.n
@@ -89,8 +89,9 @@ For \fBx\fR or \fBX\fR conversions, \fB0x\fR or \fB0X\fR (respectively)
will be added to the beginning of the result unless it is zero.
For \fBb\fR conversions, \fB0b\fR
will be added to the beginning of the result unless it is zero.
-For \fBd\fR conversions, \fB0d\fR will be added to the beginning
-of the result unless it is zero.
+For \fBd\fR conversions, \fB0d\fR there is no effect unless
+the \fB0\fR specifier is used as well: In that case, \fB0d\fR or
+\fB0D\fR (respectively) will be added to the beginning.
For all floating-point conversions (\fBe\fR, \fBE\fR, \fBf\fR,
\fBg\fR, and \fBG\fR) it guarantees that the result always
has a decimal point.
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index 34e3f28..6d065c3 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -1948,10 +1948,13 @@ Tcl_AppendFormatToObj(
}
#endif
if (useBig) {
+ int cmpResult;
if (Tcl_GetBignumFromObj(interp, segment, &big) != TCL_OK) {
goto error;
}
- isNegative = (mp_cmp_d(&big, 0) == MP_LT);
+ cmpResult = mp_cmp_d(&big, 0);
+ isNegative = (cmpResult == MP_LT);
+ if (cmpResult == MP_EQ) gotHash = 0;
if (ch == 'u') {
if (isNegative) {
msg = "unsigned bignum format is invalid";
@@ -2025,15 +2028,11 @@ Tcl_AppendFormatToObj(
if (gotHash || (ch == 'p')) {
switch (ch) {
case 'o':
- Tcl_AppendToObj(segment, "0o", 2);
- segmentLimit -= 2;
- break;
- case 'X':
- Tcl_AppendToObj(segment, "0X", 2);
segmentLimit -= 2;
break;
case 'p':
case 'x':
+ case 'X':
Tcl_AppendToObj(segment, "0x", 2);
segmentLimit -= 2;
break;
@@ -2041,10 +2040,14 @@ Tcl_AppendFormatToObj(
Tcl_AppendToObj(segment, "0b", 2);
segmentLimit -= 2;
break;
+#if TCL_MAJOR_VERSION < 9
case 'd':
- Tcl_AppendToObj(segment, "0d", 2);
- segmentLimit -= 2;
+ if (gotZero) {
+ Tcl_AppendToObj(segment, "0d", 2);
+ segmentLimit -= 2;
+ }
break;
+#endif
}
}
@@ -2249,6 +2252,8 @@ Tcl_AppendFormatToObj(
break;
}
+ case 'a':
+ case 'A':
case 'e':
case 'E':
case 'f':
@@ -2317,6 +2322,12 @@ Tcl_AppendFormatToObj(
errCode = "OVERFLOW";
goto errorMsg;
}
+ if (ch == 'A') {
+ char *p = TclGetString(segment) + 1;
+ *p = 'x';
+ p = strchr(p, 'P');
+ if (p) *p = 'p';
+ }
break;
}
default:
diff --git a/generic/tclTomMath.h b/generic/tclTomMath.h
index c8b2a87..df54ff5 100644
--- a/generic/tclTomMath.h
+++ b/generic/tclTomMath.h
@@ -273,7 +273,7 @@ int mp_set_long(mp_int *a, unsigned long b);
/* set a platform dependent unsigned long long value */
/*
-int mp_set_long_long(mp_int *a, Tcl_WideUInt b);
+int mp_set_long_long(mp_int *a, unsigned long long b);
*/
/* get a 32-bit value */
@@ -288,7 +288,7 @@ unsigned long mp_get_long(const mp_int *a);
/* get a platform dependent unsigned long long value */
/*
-Tcl_WideUInt mp_get_long_long(const mp_int *a);
+unsigned long long mp_get_long_long(const mp_int *a);
*/
/* initialize and set a digit */
@@ -323,7 +323,7 @@ int mp_import(mp_int *rop, size_t count, int order, size_t size, int endian, siz
/* export binary data */
/*
-int mp_export(void *rop, size_t *countp, int order, size_t size, int endian, size_t nails, mp_int *op);
+int mp_export(void *rop, size_t *countp, int order, size_t size, int endian, size_t nails, const mp_int *op);
*/
/* ---> digit manipulation <--- */
@@ -577,7 +577,7 @@ int mp_reduce_setup(mp_int *a, const mp_int *b);
* compute the reduction as -1 * mp_reduce(mp_abs(a)) [pseudo code].
*/
/*
-int mp_reduce(mp_int *a, const mp_int *b, mp_int *c);
+int mp_reduce(mp_int *a, const mp_int *b, const mp_int *c);
*/
/* setups the montgomery reduction */
@@ -639,7 +639,7 @@ int mp_reduce_2k_setup_l(const mp_int *a, mp_int *d);
/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
/*
-int mp_reduce_2k_l(mp_int *a, const mp_int *n, mp_int *d);
+int mp_reduce_2k_l(mp_int *a, const mp_int *n, const mp_int *d);
*/
/* d = a**b (mod c) */
diff --git a/libtommath/bn_mp_2expt.c b/libtommath/bn_mp_2expt.c
index bdc868f..701144c 100644
--- a/libtommath/bn_mp_2expt.c
+++ b/libtommath/bn_mp_2expt.c
@@ -20,8 +20,7 @@
* Simple algorithm which zeroes the int, grows it then just sets one bit
* as required.
*/
-int
-mp_2expt(mp_int *a, int b)
+int mp_2expt(mp_int *a, int b)
{
int res;
diff --git a/libtommath/bn_mp_abs.c b/libtommath/bn_mp_abs.c
index 03904d2..9b6bcec 100644
--- a/libtommath/bn_mp_abs.c
+++ b/libtommath/bn_mp_abs.c
@@ -19,8 +19,7 @@
*
* Simple function copies the input and fixes the sign to positive
*/
-int
-mp_abs(const mp_int *a, mp_int *b)
+int mp_abs(const mp_int *a, mp_int *b)
{
int res;
diff --git a/libtommath/bn_mp_add_d.c b/libtommath/bn_mp_add_d.c
index 5270d27..e5ede1f 100644
--- a/libtommath/bn_mp_add_d.c
+++ b/libtommath/bn_mp_add_d.c
@@ -16,8 +16,7 @@
*/
/* single digit addition */
-int
-mp_add_d(const mp_int *a, mp_digit b, mp_int *c)
+int mp_add_d(const mp_int *a, mp_digit b, mp_int *c)
{
int res, ix, oldused;
mp_digit *tmpa, *tmpc, mu;
diff --git a/libtommath/bn_mp_addmod.c b/libtommath/bn_mp_addmod.c
index 5aee233..0d612c3 100644
--- a/libtommath/bn_mp_addmod.c
+++ b/libtommath/bn_mp_addmod.c
@@ -16,8 +16,7 @@
*/
/* d = a + b (mod c) */
-int
-mp_addmod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d)
+int mp_addmod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d)
{
int res;
mp_int t;
diff --git a/libtommath/bn_mp_and.c b/libtommath/bn_mp_and.c
index c6e8cf7..09ff772 100644
--- a/libtommath/bn_mp_and.c
+++ b/libtommath/bn_mp_and.c
@@ -16,8 +16,7 @@
*/
/* AND two ints together */
-int
-mp_and(const mp_int *a, const mp_int *b, mp_int *c)
+int mp_and(const mp_int *a, const mp_int *b, mp_int *c)
{
int res, ix, px;
mp_int t;
diff --git a/libtommath/bn_mp_clamp.c b/libtommath/bn_mp_clamp.c
index e5c8907..3853914 100644
--- a/libtommath/bn_mp_clamp.c
+++ b/libtommath/bn_mp_clamp.c
@@ -22,8 +22,7 @@
* Typically very fast. Also fixes the sign if there
* are no more leading digits
*/
-void
-mp_clamp(mp_int *a)
+void mp_clamp(mp_int *a)
{
/* decrease used while the most significant digit is
* zero.
diff --git a/libtommath/bn_mp_clear.c b/libtommath/bn_mp_clear.c
index eada2d7..fcf4d61 100644
--- a/libtommath/bn_mp_clear.c
+++ b/libtommath/bn_mp_clear.c
@@ -16,8 +16,7 @@
*/
/* clear one (frees) */
-void
-mp_clear(mp_int *a)
+void mp_clear(mp_int *a)
{
int i;
diff --git a/libtommath/bn_mp_cmp.c b/libtommath/bn_mp_cmp.c
index 37f616e..a33d483 100644
--- a/libtommath/bn_mp_cmp.c
+++ b/libtommath/bn_mp_cmp.c
@@ -16,8 +16,7 @@
*/
/* compare two ints (signed)*/
-int
-mp_cmp(const mp_int *a, const mp_int *b)
+int mp_cmp(const mp_int *a, const mp_int *b)
{
/* compare based on sign */
if (a->sign != b->sign) {
diff --git a/libtommath/bn_mp_copy.c b/libtommath/bn_mp_copy.c
index 0f31138..17816e8 100644
--- a/libtommath/bn_mp_copy.c
+++ b/libtommath/bn_mp_copy.c
@@ -16,8 +16,7 @@
*/
/* copy, b = a */
-int
-mp_copy(const mp_int *a, mp_int *b)
+int mp_copy(const mp_int *a, mp_int *b)
{
int res, n;
diff --git a/libtommath/bn_mp_count_bits.c b/libtommath/bn_mp_count_bits.c
index f2cd190..7424581 100644
--- a/libtommath/bn_mp_count_bits.c
+++ b/libtommath/bn_mp_count_bits.c
@@ -16,8 +16,7 @@
*/
/* returns the number of bits in an int */
-int
-mp_count_bits(const mp_int *a)
+int mp_count_bits(const mp_int *a)
{
int r;
mp_digit q;
diff --git a/libtommath/bn_mp_div.c b/libtommath/bn_mp_div.c
index 6bad443..dbfdc03 100644
--- a/libtommath/bn_mp_div.c
+++ b/libtommath/bn_mp_div.c
@@ -167,7 +167,7 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
t = y.used - 1;
/* while (x >= y*b**n-t) do { q[n-t] += 1; x -= y*b**{n-t} } */
- if ((res = mp_lshd(&y, n - t)) != MP_OKAY) { /* y = y*b**{n-t} */
+ if ((res = mp_lshd(&y, n - t)) != MP_OKAY) { /* y = y*b**{n-t} */
goto LBL_Y;
}
diff --git a/libtommath/bn_mp_div_3.c b/libtommath/bn_mp_div_3.c
index 8011965..9cc8caa 100644
--- a/libtommath/bn_mp_div_3.c
+++ b/libtommath/bn_mp_div_3.c
@@ -16,8 +16,7 @@
*/
/* divide by three (based on routine from MPI and the GMP manual) */
-int
-mp_div_3(const mp_int *a, mp_int *c, mp_digit *d)
+int mp_div_3(const mp_int *a, mp_int *c, mp_digit *d)
{
mp_int q;
mp_word w, t;
diff --git a/libtommath/bn_mp_div_d.c b/libtommath/bn_mp_div_d.c
index 9997646..c408602 100644
--- a/libtommath/bn_mp_div_d.c
+++ b/libtommath/bn_mp_div_d.c
@@ -15,23 +15,6 @@
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
-static int s_is_power_of_two(mp_digit b, int *p)
-{
- int x;
-
- /* quick out - if (b & (b-1)) isn't zero, b isn't a power of two */
- if ((b == 0) || ((b & (b-1)) != 0)) {
- return 0;
- }
- for (x = 1; x < DIGIT_BIT; x++) {
- if (b == (((mp_digit)1)<<x)) {
- *p = x;
- return 1;
- }
- }
- return 0;
-}
-
/* single digit division (based on routine from MPI) */
int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
{
@@ -57,7 +40,12 @@ int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
}
/* power of two ? */
- if (s_is_power_of_two(b, &ix) == 1) {
+ if (((b & (b-1)) == 0)) {
+ for (ix = 1; ix < DIGIT_BIT; ix++) {
+ if (b == (((mp_digit)1)<<ix)) {
+ break;
+ }
+ }
if (d != NULL) {
*d = a->dp[0] & ((((mp_digit)1)<<ix) - 1);
}
diff --git a/libtommath/bn_mp_dr_reduce.c b/libtommath/bn_mp_dr_reduce.c
index 17ab289..1ccb669 100644
--- a/libtommath/bn_mp_dr_reduce.c
+++ b/libtommath/bn_mp_dr_reduce.c
@@ -29,8 +29,7 @@
*
* Input x must be in the range 0 <= x <= (n-1)**2
*/
-int
-mp_dr_reduce(mp_int *x, const mp_int *n, mp_digit k)
+int mp_dr_reduce(mp_int *x, const mp_int *n, mp_digit k)
{
int err, i, m;
mp_word r;
diff --git a/libtommath/bn_mp_dr_setup.c b/libtommath/bn_mp_dr_setup.c
index 5dff995..af0e213 100644
--- a/libtommath/bn_mp_dr_setup.c
+++ b/libtommath/bn_mp_dr_setup.c
@@ -21,8 +21,7 @@ void mp_dr_setup(const mp_int *a, mp_digit *d)
/* the casts are required if DIGIT_BIT is one less than
* the number of bits in a mp_digit [e.g. DIGIT_BIT==31]
*/
- *d = (mp_digit)((((mp_word)1) << ((mp_word)DIGIT_BIT)) -
- ((mp_word)a->dp[0]));
+ *d = (mp_digit)((((mp_word)1) << ((mp_word)DIGIT_BIT)) - ((mp_word)a->dp[0]));
}
#endif
diff --git a/libtommath/bn_mp_exch.c b/libtommath/bn_mp_exch.c
index a95560a..2bc635f 100644
--- a/libtommath/bn_mp_exch.c
+++ b/libtommath/bn_mp_exch.c
@@ -18,8 +18,7 @@
/* swap the elements of two integers, for cases where you can't simply swap the
* mp_int pointers around
*/
-void
-mp_exch(mp_int *a, mp_int *b)
+void mp_exch(mp_int *a, mp_int *b)
{
mp_int t;
diff --git a/libtommath/bn_mp_export.c b/libtommath/bn_mp_export.c
index 43228a8..4276f4f 100644
--- a/libtommath/bn_mp_export.c
+++ b/libtommath/bn_mp_export.c
@@ -19,7 +19,7 @@
* see http://gmplib.org/manual/Integer-Import-and-Export.html
*/
int mp_export(void *rop, size_t *countp, int order, size_t size,
- int endian, size_t nails, mp_int *op)
+ int endian, size_t nails, const mp_int *op)
{
int result;
size_t odd_nails, nail_bytes, i, j, bits, count;
@@ -53,11 +53,9 @@ int mp_export(void *rop, size_t *countp, int order, size_t size,
for (i = 0; i < count; ++i) {
for (j = 0; j < size; ++j) {
- unsigned char *byte = (
- (unsigned char *)rop +
- (((order == -1) ? i : ((count - 1) - i)) * size) +
- ((endian == -1) ? j : ((size - 1) - j))
- );
+ unsigned char *byte = (unsigned char *)rop +
+ (((order == -1) ? i : ((count - 1) - i)) * size) +
+ ((endian == -1) ? j : ((size - 1) - j));
if (j >= (size - nail_bytes)) {
*byte = 0;
diff --git a/libtommath/bn_mp_exptmod_fast.c b/libtommath/bn_mp_exptmod_fast.c
index 08c6bc3..4a188d0 100644
--- a/libtommath/bn_mp_exptmod_fast.c
+++ b/libtommath/bn_mp_exptmod_fast.c
@@ -24,9 +24,9 @@
*/
#ifdef MP_LOW_MEM
-#define TAB_SIZE 32
+# define TAB_SIZE 32
#else
-#define TAB_SIZE 256
+# define TAB_SIZE 256
#endif
int mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode)
diff --git a/libtommath/bn_mp_exteuclid.c b/libtommath/bn_mp_exteuclid.c
index adaea86..08e5ff2 100644
--- a/libtommath/bn_mp_exteuclid.c
+++ b/libtommath/bn_mp_exteuclid.c
@@ -20,7 +20,7 @@
*/
int mp_exteuclid(const mp_int *a, const mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3)
{
- mp_int u1,u2,u3,v1,v2,v3,t1,t2,t3,q,tmp;
+ mp_int u1, u2, u3, v1, v2, v3, t1, t2, t3, q, tmp;
int err;
if ((err = mp_init_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL)) != MP_OKAY) {
diff --git a/libtommath/bn_mp_get_int.c b/libtommath/bn_mp_get_int.c
index 5d26ce9..f4a347f 100644
--- a/libtommath/bn_mp_get_int.c
+++ b/libtommath/bn_mp_get_int.c
@@ -26,13 +26,13 @@ unsigned long mp_get_int(const mp_int *a)
}
/* get number of digits of the lsb we have to read */
- i = MIN(a->used,(int)(((sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
+ i = MIN(a->used, (int)(((sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
/* get most significant digit of result */
- res = DIGIT(a,i);
+ res = DIGIT(a, i);
while (--i >= 0) {
- res = (res << DIGIT_BIT) | DIGIT(a,i);
+ res = (res << DIGIT_BIT) | DIGIT(a, i);
}
/* force result to 32-bits always so it is consistent on non 32-bit platforms */
diff --git a/libtommath/bn_mp_get_long.c b/libtommath/bn_mp_get_long.c
index ea9ac43..3fc7c35 100644
--- a/libtommath/bn_mp_get_long.c
+++ b/libtommath/bn_mp_get_long.c
@@ -26,14 +26,14 @@ unsigned long mp_get_long(const mp_int *a)
}
/* get number of digits of the lsb we have to read */
- i = MIN(a->used,(int)(((sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
+ i = MIN(a->used, (int)(((sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
/* get most significant digit of result */
- res = DIGIT(a,i);
+ res = DIGIT(a, i);
#if (ULONG_MAX != 0xffffffffuL) || (DIGIT_BIT < 32)
while (--i >= 0) {
- res = (res << DIGIT_BIT) | DIGIT(a,i);
+ res = (res << DIGIT_BIT) | DIGIT(a, i);
}
#endif
return res;
diff --git a/libtommath/bn_mp_get_long_long.c b/libtommath/bn_mp_get_long_long.c
index 111b469..a363f60 100644
--- a/libtommath/bn_mp_get_long_long.c
+++ b/libtommath/bn_mp_get_long_long.c
@@ -26,14 +26,14 @@ Tcl_WideUInt mp_get_long_long(const mp_int *a)
}
/* get number of digits of the lsb we have to read */
- i = MIN(a->used,(int)(((sizeof(Tcl_WideUInt) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
+ i = MIN(a->used, (int)(((sizeof(Tcl_WideUInt) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
/* get most significant digit of result */
- res = DIGIT(a,i);
+ res = DIGIT(a, i);
#if DIGIT_BIT < 64
while (--i >= 0) {
- res = (res << DIGIT_BIT) | DIGIT(a,i);
+ res = (res << DIGIT_BIT) | DIGIT(a, i);
}
#endif
return res;
diff --git a/libtommath/bn_mp_import.c b/libtommath/bn_mp_import.c
index 50bee2e..afd735e 100644
--- a/libtommath/bn_mp_import.c
+++ b/libtommath/bn_mp_import.c
@@ -46,14 +46,11 @@ int mp_import(mp_int *rop, size_t count, int order, size_t size,
for (i = 0; i < count; ++i) {
for (j = 0; j < (size - nail_bytes); ++j) {
- unsigned char byte = *(
- (unsigned char *)op +
- (((order == 1) ? i : ((count - 1) - i)) * size) +
- ((endian == 1) ? (j + nail_bytes) : (((size - 1) - j) - nail_bytes))
- );
+ unsigned char byte = *((unsigned char *)op +
+ (((order == 1) ? i : ((count - 1) - i)) * size) +
+ ((endian == 1) ? (j + nail_bytes) : (((size - 1) - j) - nail_bytes)));
- if (
- (result = mp_mul_2d(rop, ((j == 0) ? (8 - odd_nails) : 8), rop)) != MP_OKAY) {
+ if ((result = mp_mul_2d(rop, ((j == 0) ? (8 - odd_nails) : 8), rop)) != MP_OKAY) {
return result;
}
diff --git a/libtommath/bn_mp_is_square.c b/libtommath/bn_mp_is_square.c
index 4d8612f..dd5150e 100644
--- a/libtommath/bn_mp_is_square.c
+++ b/libtommath/bn_mp_is_square.c
@@ -38,7 +38,7 @@ static const char rem_105[105] = {
};
/* Store non-zero to ret if arg is square, and zero if not */
-int mp_is_square(const mp_int *arg,int *ret)
+int mp_is_square(const mp_int *arg, int *ret)
{
int res;
mp_digit c;
@@ -58,12 +58,12 @@ int mp_is_square(const mp_int *arg,int *ret)
}
/* First check mod 128 (suppose that DIGIT_BIT is at least 7) */
- if (rem_128[127 & DIGIT(arg,0)] == 1) {
+ if (rem_128[127 & DIGIT(arg, 0)] == 1) {
return MP_OKAY;
}
/* Next check mod 105 (3*5*7) */
- if ((res = mp_mod_d(arg,105,&c)) != MP_OKAY) {
+ if ((res = mp_mod_d(arg, 105, &c)) != MP_OKAY) {
return res;
}
if (rem_105[c] == 1) {
@@ -71,10 +71,10 @@ int mp_is_square(const mp_int *arg,int *ret)
}
- if ((res = mp_init_set_int(&t,11L*13L*17L*19L*23L*29L*31L)) != MP_OKAY) {
+ if ((res = mp_init_set_int(&t, 11L*13L*17L*19L*23L*29L*31L)) != MP_OKAY) {
return res;
}
- if ((res = mp_mod(arg,&t,&t)) != MP_OKAY) {
+ if ((res = mp_mod(arg, &t, &t)) != MP_OKAY) {
goto ERR;
}
r = mp_get_int(&t);
@@ -91,14 +91,14 @@ int mp_is_square(const mp_int *arg,int *ret)
if (((1L<<(r%31)) & 0x6DE2B848L) != 0L) goto ERR;
/* Final check - is sqr(sqrt(arg)) == arg ? */
- if ((res = mp_sqrt(arg,&t)) != MP_OKAY) {
+ if ((res = mp_sqrt(arg, &t)) != MP_OKAY) {
goto ERR;
}
- if ((res = mp_sqr(&t,&t)) != MP_OKAY) {
+ if ((res = mp_sqr(&t, &t)) != MP_OKAY) {
goto ERR;
}
- *ret = (mp_cmp_mag(&t,arg) == MP_EQ) ? MP_YES : MP_NO;
+ *ret = (mp_cmp_mag(&t, arg) == MP_EQ) ? MP_YES : MP_NO;
ERR:
mp_clear(&t);
return res;
diff --git a/libtommath/bn_mp_mod.c b/libtommath/bn_mp_mod.c
index a7525c0..64e73ea 100644
--- a/libtommath/bn_mp_mod.c
+++ b/libtommath/bn_mp_mod.c
@@ -16,8 +16,7 @@
*/
/* c = a mod b, 0 <= c < b if b > 0, b < c <= 0 if b < 0 */
-int
-mp_mod(const mp_int *a, const mp_int *b, mp_int *c)
+int mp_mod(const mp_int *a, const mp_int *b, mp_int *c)
{
mp_int t;
int res;
diff --git a/libtommath/bn_mp_mod_2d.c b/libtommath/bn_mp_mod_2d.c
index 31997d3..8e69757 100644
--- a/libtommath/bn_mp_mod_2d.c
+++ b/libtommath/bn_mp_mod_2d.c
@@ -16,8 +16,7 @@
*/
/* calc a value mod 2**b */
-int
-mp_mod_2d(const mp_int *a, int b, mp_int *c)
+int mp_mod_2d(const mp_int *a, int b, mp_int *c)
{
int x, res;
diff --git a/libtommath/bn_mp_mod_d.c b/libtommath/bn_mp_mod_d.c
index 5217aa4..9a24e78 100644
--- a/libtommath/bn_mp_mod_d.c
+++ b/libtommath/bn_mp_mod_d.c
@@ -15,8 +15,7 @@
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
-int
-mp_mod_d(const mp_int *a, mp_digit b, mp_digit *c)
+int mp_mod_d(const mp_int *a, mp_digit b, mp_digit *c)
{
return mp_div_d(a, b, NULL, c);
}
diff --git a/libtommath/bn_mp_montgomery_reduce.c b/libtommath/bn_mp_montgomery_reduce.c
index e9f6c1c..a38173e 100644
--- a/libtommath/bn_mp_montgomery_reduce.c
+++ b/libtommath/bn_mp_montgomery_reduce.c
@@ -16,8 +16,7 @@
*/
/* computes xR**-1 == x (mod N) via Montgomery Reduction */
-int
-mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
+int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
{
int ix, res, digs;
mp_digit mu;
diff --git a/libtommath/bn_mp_montgomery_setup.c b/libtommath/bn_mp_montgomery_setup.c
index 37069c3..685ba51 100644
--- a/libtommath/bn_mp_montgomery_setup.c
+++ b/libtommath/bn_mp_montgomery_setup.c
@@ -16,8 +16,7 @@
*/
/* setups the montgomery reduction stuff */
-int
-mp_montgomery_setup(const mp_int *n, mp_digit *rho)
+int mp_montgomery_setup(const mp_int *n, mp_digit *rho)
{
mp_digit x, b;
diff --git a/libtommath/bn_mp_mul.c b/libtommath/bn_mp_mul.c
index 6e7f956..71d523d 100644
--- a/libtommath/bn_mp_mul.c
+++ b/libtommath/bn_mp_mul.c
@@ -51,7 +51,7 @@ int mp_mul(const mp_int *a, const mp_int *b, mp_int *c)
#endif
{
#ifdef BN_S_MP_MUL_DIGS_C
- res = s_mp_mul(a, b, c); /* uses s_mp_mul_digs */
+ res = s_mp_mul(a, b, c); /* uses s_mp_mul_digs */
#else
res = MP_VAL;
#endif
diff --git a/libtommath/bn_mp_mul_d.c b/libtommath/bn_mp_mul_d.c
index 98b99c9..0f6d03e 100644
--- a/libtommath/bn_mp_mul_d.c
+++ b/libtommath/bn_mp_mul_d.c
@@ -16,8 +16,7 @@
*/
/* multiply by a digit */
-int
-mp_mul_d(const mp_int *a, mp_digit b, mp_int *c)
+int mp_mul_d(const mp_int *a, mp_digit b, mp_int *c)
{
mp_digit u, *tmpa, *tmpc;
mp_word r;
@@ -51,10 +50,10 @@ mp_mul_d(const mp_int *a, mp_digit b, mp_int *c)
r = (mp_word)u + ((mp_word)*tmpa++ * (mp_word)b);
/* mask off higher bits to get a single digit */
- *tmpc++ = (mp_digit)(r & ((mp_word) MP_MASK));
+ *tmpc++ = (mp_digit)(r & ((mp_word)MP_MASK));
/* send carry into next iteration */
- u = (mp_digit)(r >> ((mp_word) DIGIT_BIT));
+ u = (mp_digit)(r >> ((mp_word)DIGIT_BIT));
}
/* store final carry [if any] and increment ix offset */
diff --git a/libtommath/bn_mp_radix_size.c b/libtommath/bn_mp_radix_size.c
index edcf618..29355cb 100644
--- a/libtommath/bn_mp_radix_size.c
+++ b/libtommath/bn_mp_radix_size.c
@@ -58,7 +58,7 @@ int mp_radix_size(const mp_int *a, int radix, int *size)
/* fetch out all of the digits */
while (mp_iszero(&t) == MP_NO) {
- if ((res = mp_div_d(&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
+ if ((res = mp_div_d(&t, (mp_digit)radix, &t, &d)) != MP_OKAY) {
mp_clear(&t);
return res;
}
diff --git a/libtommath/bn_mp_rand.c b/libtommath/bn_mp_rand.c
index 7ac01dc..92a9a97 100644
--- a/libtommath/bn_mp_rand.c
+++ b/libtommath/bn_mp_rand.c
@@ -41,8 +41,7 @@ static mp_digit s_gen_random(void)
return d;
}
-int
-mp_rand(mp_int *a, int digits)
+int mp_rand(mp_int *a, int digits)
{
int res;
mp_digit d;
diff --git a/libtommath/bn_mp_read_radix.c b/libtommath/bn_mp_read_radix.c
index 6e57ed5..bc31cc5 100644
--- a/libtommath/bn_mp_read_radix.c
+++ b/libtommath/bn_mp_read_radix.c
@@ -60,10 +60,10 @@ int mp_read_radix(mp_int *a, const char *str, int radix)
* to the number, otherwise exit the loop.
*/
if (y < radix) {
- if ((res = mp_mul_d(a, (mp_digit) radix, a)) != MP_OKAY) {
+ if ((res = mp_mul_d(a, (mp_digit)radix, a)) != MP_OKAY) {
return res;
}
- if ((res = mp_add_d(a, (mp_digit) y, a)) != MP_OKAY) {
+ if ((res = mp_add_d(a, (mp_digit)y, a)) != MP_OKAY) {
return res;
}
} else {
diff --git a/libtommath/bn_mp_reduce.c b/libtommath/bn_mp_reduce.c
index 6665acb..bbc521f 100644
--- a/libtommath/bn_mp_reduce.c
+++ b/libtommath/bn_mp_reduce.c
@@ -19,7 +19,7 @@
* precomputed via mp_reduce_setup.
* From HAC pp.604 Algorithm 14.42
*/
-int mp_reduce(mp_int *x, const mp_int *m, mp_int *mu)
+int mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu)
{
mp_int q;
int res, um = m->used;
diff --git a/libtommath/bn_mp_reduce_2k_l.c b/libtommath/bn_mp_reduce_2k_l.c
index 3b23a37..23381bf 100644
--- a/libtommath/bn_mp_reduce_2k_l.c
+++ b/libtommath/bn_mp_reduce_2k_l.c
@@ -19,7 +19,7 @@
This differs from reduce_2k since "d" can be larger
than a single digit.
*/
-int mp_reduce_2k_l(mp_int *a, const mp_int *n, mp_int *d)
+int mp_reduce_2k_l(mp_int *a, const mp_int *n, const mp_int *d)
{
mp_int q;
int p, res;
diff --git a/libtommath/bn_mp_sqr.c b/libtommath/bn_mp_sqr.c
index 0fd077c..2b71097 100644
--- a/libtommath/bn_mp_sqr.c
+++ b/libtommath/bn_mp_sqr.c
@@ -16,8 +16,7 @@
*/
/* computes b = a*a */
-int
-mp_sqr(const mp_int *a, mp_int *b)
+int mp_sqr(const mp_int *a, mp_int *b)
{
int res;
diff --git a/libtommath/bn_mp_sqrmod.c b/libtommath/bn_mp_sqrmod.c
index b8265fe..c3c7ec9 100644
--- a/libtommath/bn_mp_sqrmod.c
+++ b/libtommath/bn_mp_sqrmod.c
@@ -16,8 +16,7 @@
*/
/* c = a * a (mod b) */
-int
-mp_sqrmod(const mp_int *a, const mp_int *b, mp_int *c)
+int mp_sqrmod(const mp_int *a, const mp_int *b, mp_int *c)
{
int res;
mp_int t;
diff --git a/libtommath/bn_mp_sub.c b/libtommath/bn_mp_sub.c
index b865dbd..19cb65e 100644
--- a/libtommath/bn_mp_sub.c
+++ b/libtommath/bn_mp_sub.c
@@ -16,8 +16,7 @@
*/
/* high level subtraction (handles signs) */
-int
-mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
+int mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
{
int sa, sb, res;
diff --git a/libtommath/bn_mp_sub_d.c b/libtommath/bn_mp_sub_d.c
index e22c35c..4d66a90 100644
--- a/libtommath/bn_mp_sub_d.c
+++ b/libtommath/bn_mp_sub_d.c
@@ -16,8 +16,7 @@
*/
/* single digit subtraction */
-int
-mp_sub_d(const mp_int *a, mp_digit b, mp_int *c)
+int mp_sub_d(const mp_int *a, mp_digit b, mp_int *c)
{
mp_digit *tmpa, *tmpc, mu;
int res, ix, oldused;
diff --git a/libtommath/bn_mp_submod.c b/libtommath/bn_mp_submod.c
index 9a45f6d..c4db397 100644
--- a/libtommath/bn_mp_submod.c
+++ b/libtommath/bn_mp_submod.c
@@ -16,8 +16,7 @@
*/
/* d = a - b (mod c) */
-int
-mp_submod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d)
+int mp_submod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d)
{
int res;
mp_int t;
diff --git a/libtommath/bn_mp_toom_sqr.c b/libtommath/bn_mp_toom_sqr.c
index 921d6a5..b985435 100644
--- a/libtommath/bn_mp_toom_sqr.c
+++ b/libtommath/bn_mp_toom_sqr.c
@@ -16,8 +16,7 @@
*/
/* squaring using Toom-Cook 3-way algorithm */
-int
-mp_toom_sqr(const mp_int *a, mp_int *b)
+int mp_toom_sqr(const mp_int *a, mp_int *b)
{
mp_int w0, w1, w2, w3, w4, tmp1, a0, a1, a2;
int res, B;
diff --git a/libtommath/bn_mp_toradix.c b/libtommath/bn_mp_toradix.c
index 79960f0..7dd6e4f 100644
--- a/libtommath/bn_mp_toradix.c
+++ b/libtommath/bn_mp_toradix.c
@@ -48,7 +48,7 @@ int mp_toradix(const mp_int *a, char *str, int radix)
digs = 0;
while (mp_iszero(&t) == MP_NO) {
- if ((res = mp_div_d(&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
+ if ((res = mp_div_d(&t, (mp_digit)radix, &t, &d)) != MP_OKAY) {
mp_clear(&t);
return res;
}
diff --git a/libtommath/bn_mp_toradix_n.c b/libtommath/bn_mp_toradix_n.c
index 5d766bd..ef885fc 100644
--- a/libtommath/bn_mp_toradix_n.c
+++ b/libtommath/bn_mp_toradix_n.c
@@ -61,7 +61,7 @@ int mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen)
/* no more room */
break;
}
- if ((res = mp_div_d(&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
+ if ((res = mp_div_d(&t, (mp_digit)radix, &t, &d)) != MP_OKAY) {
mp_clear(&t);
return res;
}
diff --git a/libtommath/bn_mp_xor.c b/libtommath/bn_mp_xor.c
index 91bcd02..9ebc53a 100644
--- a/libtommath/bn_mp_xor.c
+++ b/libtommath/bn_mp_xor.c
@@ -16,8 +16,7 @@
*/
/* XOR two ints together */
-int
-mp_xor(const mp_int *a, const mp_int *b, mp_int *c)
+int mp_xor(const mp_int *a, const mp_int *b, mp_int *c)
{
int res, ix, px;
mp_int t;
diff --git a/libtommath/bn_reverse.c b/libtommath/bn_reverse.c
index c3e7cf2..71e3d03 100644
--- a/libtommath/bn_reverse.c
+++ b/libtommath/bn_reverse.c
@@ -16,8 +16,7 @@
*/
/* reverse an array, used for radix code */
-void
-bn_reverse(unsigned char *s, int len)
+void bn_reverse(unsigned char *s, int len)
{
int ix, iy;
unsigned char t;
diff --git a/libtommath/bn_s_mp_add.c b/libtommath/bn_s_mp_add.c
index 415521f..2046722 100644
--- a/libtommath/bn_s_mp_add.c
+++ b/libtommath/bn_s_mp_add.c
@@ -16,8 +16,7 @@
*/
/* low level addition, based on HAC pp.594, Algorithm 14.7 */
-int
-s_mp_add(const mp_int *a, const mp_int *b, mp_int *c)
+int s_mp_add(const mp_int *a, const mp_int *b, mp_int *c)
{
const mp_int *x;
int olduse, res, min, max;
diff --git a/libtommath/bn_s_mp_exptmod.c b/libtommath/bn_s_mp_exptmod.c
index e73c12e..a886361 100644
--- a/libtommath/bn_s_mp_exptmod.c
+++ b/libtommath/bn_s_mp_exptmod.c
@@ -15,9 +15,9 @@
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
#ifdef MP_LOW_MEM
-#define TAB_SIZE 32
+# define TAB_SIZE 32
#else
-#define TAB_SIZE 256
+# define TAB_SIZE 256
#endif
int s_mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode)
@@ -25,7 +25,7 @@ int s_mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, i
mp_int M[TAB_SIZE], res, mu;
mp_digit buf;
int err, bitbuf, bitcpy, bitcnt, mode, digidx, x, y, winsize;
- int (*redux)(mp_int *,const mp_int *,mp_int *);
+ int (*redux)(mp_int *, const mp_int *, const mp_int *);
/* find window size */
x = mp_count_bits(X);
@@ -152,7 +152,7 @@ int s_mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, i
}
/* read next digit and reset the bitcnt */
buf = X->dp[digidx--];
- bitcnt = (int) DIGIT_BIT;
+ bitcnt = (int)DIGIT_BIT;
}
/* grab the next msb from the exponent */
diff --git a/libtommath/bn_s_mp_mul_high_digs.c b/libtommath/bn_s_mp_mul_high_digs.c
index 0a829b9..37c108e 100644
--- a/libtommath/bn_s_mp_mul_high_digs.c
+++ b/libtommath/bn_s_mp_mul_high_digs.c
@@ -18,8 +18,7 @@
/* multiplies |a| * |b| and does not compute the lower digs digits
* [meant to get the higher part of the product]
*/
-int
-s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
+int s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
{
mp_int t;
int res, pa, pb, ix, iy;
diff --git a/libtommath/bn_s_mp_sqr.c b/libtommath/bn_s_mp_sqr.c
index e07bf1c..aae06eb 100644
--- a/libtommath/bn_s_mp_sqr.c
+++ b/libtommath/bn_s_mp_sqr.c
@@ -38,10 +38,10 @@ int s_mp_sqr(const mp_int *a, mp_int *b)
((mp_word)a->dp[ix] * (mp_word)a->dp[ix]);
/* store lower part in result */
- t.dp[ix+ix] = (mp_digit)(r & ((mp_word) MP_MASK));
+ t.dp[ix+ix] = (mp_digit)(r & ((mp_word)MP_MASK));
/* get the carry */
- u = (mp_digit)(r >> ((mp_word) DIGIT_BIT));
+ u = (mp_digit)(r >> ((mp_word)DIGIT_BIT));
/* left hand side of A[ix] * A[iy] */
tmpx = a->dp[ix];
diff --git a/libtommath/bn_s_mp_sub.c b/libtommath/bn_s_mp_sub.c
index 8373025..52b8096 100644
--- a/libtommath/bn_s_mp_sub.c
+++ b/libtommath/bn_s_mp_sub.c
@@ -16,8 +16,7 @@
*/
/* low level subtraction (assumes |a| > |b|), HAC pp.595 Algorithm 14.9 */
-int
-s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
+int s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
{
int olduse, res, min, max;
diff --git a/libtommath/tommath.h b/libtommath/tommath.h
index dee7ab5..50a3a81 100644
--- a/libtommath/tommath.h
+++ b/libtommath/tommath.h
@@ -33,11 +33,13 @@ extern "C" {
defined(__sparcv9) || defined(__sparc_v9__) || defined(__sparc64__) || \
defined(__ia64) || defined(__ia64__) || defined(__itanium__) || defined(_M_IA64) || \
defined(__LP64__) || defined(_LP64) || defined(__64BIT__)
-# if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT))
+# if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT) || defined(_MSC_VER))
# define MP_64BIT
# endif
#endif
+typedef unsigned long long Tcl_WideUInt;
+
/* some default configurations.
*
* A "mp_digit" must be able to hold DIGIT_BIT + 1 bits
@@ -250,7 +252,7 @@ void mp_clamp(mp_int *a);
int mp_import(mp_int *rop, size_t count, int order, size_t size, int endian, size_t nails, const void *op);
/* export binary data */
-int mp_export(void *rop, size_t *countp, int order, size_t size, int endian, size_t nails, mp_int *op);
+int mp_export(void *rop, size_t *countp, int order, size_t size, int endian, size_t nails, const mp_int *op);
/* ---> digit manipulation <--- */
@@ -408,7 +410,7 @@ int mp_reduce_setup(mp_int *a, const mp_int *b);
* Assumes that 0 < a <= b*b, note if 0 > a > -(b*b) then you can merely
* compute the reduction as -1 * mp_reduce(mp_abs(a)) [pseudo code].
*/
-int mp_reduce(mp_int *a, const mp_int *b, mp_int *c);
+int mp_reduce(mp_int *a, const mp_int *b, const mp_int *c);
/* setups the montgomery reduction */
int mp_montgomery_setup(const mp_int *a, mp_digit *mp);
@@ -446,7 +448,7 @@ int mp_reduce_is_2k_l(const mp_int *a);
int mp_reduce_2k_setup_l(const mp_int *a, mp_int *d);
/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
-int mp_reduce_2k_l(mp_int *a, const mp_int *n, mp_int *d);
+int mp_reduce_2k_l(mp_int *a, const mp_int *n, const mp_int *d);
/* d = a**b (mod c) */
int mp_exptmod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d);
diff --git a/tests/format.test b/tests/format.test
index c18378f..ed8676a 100644
--- a/tests/format.test
+++ b/tests/format.test
@@ -28,7 +28,7 @@ test format-1.1 {integer formatting} {
} { 34 16923 -12 -1}
test format-1.2 {integer formatting} {
format "%4d %4d %4d %4d %d %#x %#X" 6 34 16923 -12 -1 14 12
-} { 6 34 16923 -12 -1 0xe 0XC}
+} { 6 34 16923 -12 -1 0xe 0xC}
test format-1.3 {integer formatting} longIs32bit {
format "%4u %4u %4u %4u %d %#o" 6 34 16923 -12 -1 0
} { 6 34 16923 4294967284 -1 0}
@@ -54,10 +54,10 @@ test format-1.7.1 {integer formatting} longIs64bit {
} { 6 22 421b fffffffffffffff4}
test format-1.8 {integer formatting} longIs32bit {
format "%#x %#x %#X %#X %#x" 0 6 34 16923 -12 -1
-} {0 0x6 0X22 0X421B 0xfffffff4}
+} {0 0x6 0x22 0x421B 0xfffffff4}
test format-1.8.1 {integer formatting} longIs64bit {
format "%#x %#x %#X %#X %#x" 0 6 34 16923 -12 -1
-} {0 0x6 0X22 0X421B 0xfffffffffffffff4}
+} {0 0x6 0x22 0x421B 0xfffffffffffffff4}
test format-1.9 {integer formatting} longIs32bit {
format "%#5x %#20x %#20x %#20x %#20x" 0 6 34 16923 -12 -1
} { 0 0x6 0x22 0x421b 0xfffffff4}
@@ -80,14 +80,14 @@ test format-1.12 {integer formatting} {
format "%b %#b %#b %llb" 5 0 5 [expr {2**100}]
} {101 0 0b101 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000}
test format-1.13 {integer formatting} {
- format "%#d %#d %#d %#d %#d" 0 6 34 16923 -12 -1
-} {0d0 0d6 0d34 0d16923 -0d12}
+ format "%#0d %#0d %#0d %#0d %#0d" 0 6 34 16923 -12 -1
+} {0 0d6 0d34 0d16923 -0d12}
test format-1.14 {integer formatting} {
- format "%#5d %#20d %#20d %#20d %#20d" 0 6 34 16923 -12 -1
-} { 0d0 0d6 0d34 0d16923 -0d12}
+ format "%#05d %#020d %#020d %#020d %#020d" 0 6 34 16923 -12 -1
+} {00000 0d000000000000000006 0d000000000000000034 0d000000000000016923 -0d00000000000000012}
test format-1.15 {integer formatting} {
- format "%-#5d %-#20d %-#20d %-#20d %-#20d" 0 6 34 16923 -12 -1
-} {0d0 0d6 0d34 0d16923 -0d12 }
+ format "%-#05d %-#020d %-#020d %-#020d %-#020d" 0 6 34 16923 -12 -1
+} {00000 0d000000000000000006 0d000000000000000034 0d000000000000016923 -0d00000000000000012}
test format-2.1 {string formatting} {
diff --git a/tests/io.test b/tests/io.test
index aaceec5..5c81d52 100644
--- a/tests/io.test
+++ b/tests/io.test
@@ -5638,7 +5638,7 @@ test io-40.2 {POSIX open access modes: CREAT} {unix} {
file delete $path(test3)
set f [open $path(test3) {WRONLY CREAT} 0o600]
file stat $path(test3) stats
- set x [format "0o%o" [expr $stats(mode)&0o777]]
+ set x [format "%#o" [expr $stats(mode)&0o777]]
puts $f "line 1"
close $f
set f [open $path(test3) r]
diff --git a/win/nmakehlp.c b/win/nmakehlp.c
index 22b7b06..0439d1c 100644
--- a/win/nmakehlp.c
+++ b/win/nmakehlp.c
@@ -74,6 +74,7 @@ main(
char msg[300];
DWORD dwWritten;
int chars;
+ char *s;
/*
* Make sure children (cl.exe and link.exe) are kept quiet.
@@ -153,8 +154,13 @@ main(
&dwWritten, NULL);
return 0;
}
- printf("%s\n", GetVersionFromFile(argv[2], argv[3], *(argv[1]+2) - '0'));
- return 0;
+ s = GetVersionFromFile(argv[2], argv[3], *(argv[1]+2) - '0');
+ if (s && *s) {
+ printf("%s\n", s);
+ return 0;
+ } else
+ return 1; /* Version not found. Return non-0 exit code */
+
case 'Q':
if (argc != 3) {
chars = snprintf(msg, sizeof(msg) - 1,
diff --git a/win/tclWinFCmd.c b/win/tclWinFCmd.c
index 01af950..319ecf9 100644
--- a/win/tclWinFCmd.c
+++ b/win/tclWinFCmd.c
@@ -1611,13 +1611,11 @@ ConvertFileNameFormat(
for (i = 0; i < pathc; i++) {
Tcl_Obj *elt;
char *pathv;
- size_t pathLen;
Tcl_ListObjIndex(NULL, splitPath, i, &elt);
pathv = TclGetString(elt);
- pathLen = elt->length;
- if ((pathv[0] == '/') || ((pathLen == 3) && (pathv[1] == ':'))
+ if ((pathv[0] == '/') || ((elt->length == 3) && (pathv[1] == ':'))
|| (strcmp(pathv, ".") == 0) || (strcmp(pathv, "..") == 0)) {
/*
* Handle "/", "//machine/export", "c:/", "." or ".." by just
diff --git a/win/tclWinLoad.c b/win/tclWinLoad.c
index 26512b1..27eb8f3 100644
--- a/win/tclWinLoad.c
+++ b/win/tclWinLoad.c
@@ -66,6 +66,7 @@ TclpDlopen(
HINSTANCE hInstance;
const TCHAR *nativeName;
Tcl_LoadHandle handlePtr;
+ DWORD firstError;
/*
* First try the full path the user gave us. This is particularly
@@ -84,6 +85,12 @@ TclpDlopen(
Tcl_DString ds;
+ /*
+ * Remember the first error on load attempt to be used if the
+ * second load attempt below also fails.
+ */
+ firstError = GetLastError();
+
nativeName = Tcl_WinUtfToTChar(Tcl_GetString(pathPtr), -1, &ds);
hInstance = LoadLibraryEx(nativeName, NULL,
LOAD_WITH_ALTERED_SEARCH_PATH);
@@ -91,8 +98,21 @@ TclpDlopen(
}
if (hInstance == NULL) {
- DWORD lastError = GetLastError();
- Tcl_Obj *errMsg = Tcl_ObjPrintf("couldn't load library \"%s\": ",
+ DWORD lastError;
+ Tcl_Obj *errMsg;
+
+ /*
+ * We choose to only use the error from the second call if the first
+ * call failed due to the file not being found. Else stick to the
+ * first error for reporting purposes.
+ */
+ if (firstError == ERROR_MOD_NOT_FOUND ||
+ firstError == ERROR_DLL_NOT_FOUND)
+ lastError = GetLastError();
+ else
+ lastError = firstError;
+
+ errMsg = Tcl_ObjPrintf("couldn't load library \"%s\": ",
Tcl_GetString(pathPtr));
/*
@@ -129,7 +149,11 @@ TclpDlopen(
Tcl_AppendToObj(errMsg, "the library initialization"
" routine failed", -1);
break;
- default:
+ case ERROR_BAD_EXE_FORMAT:
+ Tcl_SetErrorCode(interp, "WIN_LOAD", "BAD_EXE_FORMAT", NULL);
+ Tcl_AppendToObj(errMsg, "Bad exe format. Possibly a 32/64-bit mismatch.", -1);
+ break;
+ default:
TclWinConvertError(lastError);
Tcl_AppendToObj(errMsg, Tcl_PosixError(interp), -1);
}