Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Fix libtommath's mp_radix_size() function such that it returns 2 for single-digit numbers. Add testcases for mp_radix_size() and mp_iseven(). Undo useless change in bn_mp_add_d.c (bring back libtommath's version). |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
06f3f845fb1210db64e1cd85ea8eff16 |
User & Date: | jan.nijtmans 2016-11-17 16:26:50.897 |
Context
2016-11-18
| ||
03:34 | Remove extra space in documentation for [file stat] check-in: 21feca063c user: andy tags: trunk | |
2016-11-17
| ||
16:27 | merge trunk check-in: f365ba1ad9 user: jan.nijtmans tags: novem | |
16:26 | Fix libtommath's mp_radix_size() function such that it returns 2 for single-digit numbers. Add testc... check-in: 06f3f845fb user: jan.nijtmans tags: trunk | |
16:24 | Fix libtommath's mp_radix_size() function such that it returns 2 for single-digit numbers. Add testc... check-in: db3a4c3b27 user: jan.nijtmans tags: core-8-6-branch | |
09:33 | Remove subdirectories of "libtommath", and various individual related files, not taking any part in ... check-in: 634ffe2b64 user: jan.nijtmans tags: trunk | |
Changes
Changes to generic/tclObj.c.
︙ | ︙ | |||
3248 3249 3250 3251 3252 3253 3254 | char *stringVal; UNPACK_BIGNUM(objPtr, bignumVal); status = mp_radix_size(&bignumVal, 10, &size); if (status != MP_OKAY) { Tcl_Panic("radix size failure in UpdateStringOfBignum"); } | | | | < < | 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 | char *stringVal; UNPACK_BIGNUM(objPtr, bignumVal); status = mp_radix_size(&bignumVal, 10, &size); if (status != MP_OKAY) { Tcl_Panic("radix size failure in UpdateStringOfBignum"); } if (size < 2) { /* * mp_radix_size() returns < 2 when more than INT_MAX bytes would be * needed to hold the string rep (because mp_radix_size ignores * integer overflow issues). * * Note that so long as we enforce our bignums to the size that fits * in a packed bignum, this branch will never be taken. */ Tcl_Panic("UpdateStringOfBignum: string length limit exceeded"); } |
︙ | ︙ |
Changes to generic/tclTestObj.c.
︙ | ︙ | |||
148 149 150 151 152 153 154 | TestbignumobjCmd( ClientData clientData, /* unused */ Tcl_Interp *interp, /* Tcl interpreter */ int objc, /* Argument count */ Tcl_Obj *const objv[]) /* Argument vector */ { const char *const subcmds[] = { | | | > | 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | TestbignumobjCmd( ClientData clientData, /* unused */ Tcl_Interp *interp, /* Tcl interpreter */ int objc, /* Argument count */ Tcl_Obj *const objv[]) /* Argument vector */ { const char *const subcmds[] = { "set", "get", "mult10", "div10", "iseven", "radixsize", NULL }; enum options { BIGNUM_SET, BIGNUM_GET, BIGNUM_MULT10, BIGNUM_DIV10, BIGNUM_ISEVEN, BIGNUM_RADIXSIZE }; int index, varIndex; const char *string; mp_int bignumValue, newValue; Tcl_Obj **varPtr; if (objc < 3) { |
︙ | ︙ | |||
270 271 272 273 274 275 276 277 278 279 280 281 282 283 | } mp_clear(&bignumValue); if (!Tcl_IsShared(varPtr[varIndex])) { Tcl_SetBignumObj(varPtr[varIndex], &newValue); } else { SetVarToObj(varPtr, varIndex, Tcl_NewBignumObj(&newValue)); } } Tcl_SetObjResult(interp, varPtr[varIndex]); return TCL_OK; } /* | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | } mp_clear(&bignumValue); if (!Tcl_IsShared(varPtr[varIndex])) { Tcl_SetBignumObj(varPtr[varIndex], &newValue); } else { SetVarToObj(varPtr, varIndex, Tcl_NewBignumObj(&newValue)); } break; case BIGNUM_ISEVEN: if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "varIndex"); return TCL_ERROR; } if (CheckIfVarUnset(interp, varPtr,varIndex)) { return TCL_ERROR; } if (Tcl_GetBignumFromObj(interp, varPtr[varIndex], &bignumValue) != TCL_OK) { return TCL_ERROR; } if (!Tcl_IsShared(varPtr[varIndex])) { Tcl_SetIntObj(varPtr[varIndex], mp_iseven(&bignumValue)); } else { SetVarToObj(varPtr, varIndex, Tcl_NewIntObj(mp_iseven(&bignumValue))); } mp_clear(&bignumValue); break; case BIGNUM_RADIXSIZE: if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "varIndex"); return TCL_ERROR; } if (CheckIfVarUnset(interp, varPtr,varIndex)) { return TCL_ERROR; } if (Tcl_GetBignumFromObj(interp, varPtr[varIndex], &bignumValue) != TCL_OK) { return TCL_ERROR; } if (mp_radix_size(&bignumValue, 10, &index) != MP_OKAY) { return TCL_ERROR; } if (!Tcl_IsShared(varPtr[varIndex])) { Tcl_SetIntObj(varPtr[varIndex], index); } else { SetVarToObj(varPtr, varIndex, Tcl_NewIntObj(index)); } mp_clear(&bignumValue); break; } Tcl_SetObjResult(interp, varPtr[varIndex]); return TCL_OK; } /* |
︙ | ︙ |
Changes to libtommath/bn_mp_add_d.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 | * The library was designed directly after the MPI library by * Michael Fromberger but has been written from scratch with * additional optimizations in place. * * The library is free for all purposes without any express * guarantee it works. * | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | * The library was designed directly after the MPI library by * Michael Fromberger but has been written from scratch with * additional optimizations in place. * * The library is free for all purposes without any express * guarantee it works. * * Tom St Denis, [email protected], http://libtom.org */ /* single digit addition */ int mp_add_d (mp_int * a, mp_digit b, mp_int * c) { int res, ix, oldused; |
︙ | ︙ | |||
33 34 35 36 37 38 39 | if (a->sign == MP_NEG && (a->used > 1 || a->dp[0] >= b)) { /* temporarily fix sign of a */ a->sign = MP_ZPOS; /* c = |a| - b */ res = mp_sub_d(a, b, c); | | | < | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | if (a->sign == MP_NEG && (a->used > 1 || a->dp[0] >= b)) { /* temporarily fix sign of a */ a->sign = MP_ZPOS; /* c = |a| - b */ res = mp_sub_d(a, b, c); /* fix sign */ a->sign = c->sign = MP_NEG; /* clamp */ mp_clamp(c); return res; } |
︙ | ︙ | |||
103 104 105 106 107 108 109 | } mp_clamp(c); return MP_OKAY; } #endif | > > > > | 102 103 104 105 106 107 108 109 110 111 112 | } mp_clamp(c); return MP_OKAY; } #endif /* $Source$ */ /* $Revision: 0.41 $ */ /* $Date: 2007-04-18 09:58:18 +0000 $ */ |
Changes to libtommath/bn_mp_radix_size.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 | * The library was designed directly after the MPI library by * Michael Fromberger but has been written from scratch with * additional optimizations in place. * * The library is free for all purposes without any express * guarantee it works. * | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | * The library was designed directly after the MPI library by * Michael Fromberger but has been written from scratch with * additional optimizations in place. * * The library is free for all purposes without any express * guarantee it works. * * Tom St Denis, [email protected], http://libtom.org */ /* returns size of ASCII reprensentation */ int mp_radix_size (mp_int * a, int radix, int *size) { int res, digs; mp_int t; |
︙ | ︙ | |||
62 63 64 65 66 67 68 | mp_clear (&t); return res; } ++digs; } mp_clear (&t); | < | < < < < < | < < < > > > > | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | mp_clear (&t); return res; } ++digs; } mp_clear (&t); /* return digs + 1, the 1 is for the NULL byte that would be required. */ *size = digs + 1; return MP_OKAY; } #endif /* $Source$ */ /* $Revision: 0.41 $ */ /* $Date: 2007-04-18 09:58:18 +0000 $ */ |
Changes to tests/obj.test.
︙ | ︙ | |||
620 621 622 623 624 625 626 627 628 629 630 631 632 633 | set x -0xffff; append x ffff list [string is integer $x] [expr { wide($x) }] } {1 -4294967295} test obj-33.7 {integer overflow on input} { set x -0x10000; append x 0000 list [string is integer $x] [expr { wide($x) }] } {0 -4294967296} if {[testConstraint testobj]} { testobj freeallvars } # cleanup ::tcltest::cleanupTests | > > > > > > > > > > > > > | 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 | set x -0xffff; append x ffff list [string is integer $x] [expr { wide($x) }] } {1 -4294967295} test obj-33.7 {integer overflow on input} { set x -0x10000; append x 0000 list [string is integer $x] [expr { wide($x) }] } {0 -4294967296} test obj-34.1 {mp_iseven} testobj { set result "" lappend result [testbignumobj set 1 0] lappend result [testbignumobj iseven 1] ; lappend result [testobj type 1] } {0 1 int} test obj-34.2 {mp_radix_size} testobj { set result "" lappend result [testbignumobj set 1 9] lappend result [testbignumobj radixsize 1] ; lappend result [testobj type 1] } {9 2 int} if {[testConstraint testobj]} { testobj freeallvars } # cleanup ::tcltest::cleanupTests |
︙ | ︙ |