Skip to content
Tcl Source Code Artifact [e72c867bd3]
Login

Artifact [e72c867bd3]

Artifact e72c867bd361f34e4a23fe898b78b7dcf464d3ed930c66966a752323215ad18a:

Ticket change [e72c867bd3] - Open ticket [1f40aa83c552f597|1f40aa83c5]: <i>crash with CFLAGS=-ftrapv</i> plus 7 other changes by jan.nijtmans on 2024-03-22 09:12:50.
D 2024-03-22T09:12:50.812
J assignee sebres
J closer nobody
J icomment Re-opening,\sbecause\sthere\sreally\sis\sa\sbug,\sdiscovered\sby\sthe\s-ftrapv\soption.\r\nFirst:\r\n<pre>\r\n$\stclsh9.0\r\n%\sclock\sscan\s27670116110564327424\s-format\s%s\r\ninteger\svalue\stoo\slarge\sto\srepresent\r\n%\sclock\sscan\s27670116110564327424\r\nAborted\r\n</pre>\r\nThe\sfirst\sanswer\sis\scorrect:\s27670116110564327424\sin\shex\sis\s0x18000000000000000,\swhich\s-\sindeed\s-\sis\stoo\slarge\sto\srepresent\sin\s64-bit.\sNow:\r\n<pre>\r\n$\stclsh9.0\r\n%\sclock\sscan\s27670116110564327423\s-format\s%s\r\n9223372036854775807\r\n%\sclock\sscan\s27670116110564327423\r\nAborted\r\n</pre>\r\n\r\nNow,\sthe\sfirst\scommand\sgives\san\s-\sincorrect\s-\sanswer:\sThe\shex\svalue\sof\s27670116110564327423\sis\s0x17fffffffffffffff,\swhich\sis\salso\stoo\slarge\sto\srepresent\sin\s64-bit.\sThe\ssecond\scrash\s-\smost\slikely\s-\shappened\sbecause\smy\sbuild\swas\swith\sCFLAGS=-ftrapv,\sand\san\soverflow\soccurred\ssomewhere\selse.\r\n\r\nCompare\sthis\swith\sTcl\s8.6:\r\n<pre>\r\n$\stclsh8.6\r\n%\sclock\sscan\s27670116110564327423\s-format\s%s\r\ninteger\svalue\stoo\slarge\sto\srepresent\r\n%\sclock\sscan\s27670116110564327423\r\n89170590265200\r\n</pre>\r\n\r\nExplanation:\sLet's\sparse\sthe\sstring\s"27670116110564327423"\swith\sfunction\s_str2wideInt().\sAfter\s19\siterations,\sthe\sstring\sis\sparsed\salmost\scompletely,\sonly\sthe\slast\sdigit\sis\smissing.\s"prev"\shas\sthe\svalue\s2767011611056432742,\swhich\sis\s0x2666666666666666\sin\shex,\severything\sfine.\sThen\s"val"\sis\smultiplied\sby\s10\sand\sthe\slast\sdigit\sis\sadded.\sResult\sis\s0x17fffffffffffffff,\swhich\soverflows\sand\sthus\sis\struncated\sto\s0x7fffffffffffffff.\sThis\smeans\sval\s>\sprev,\sand\sthe\sfunction\sreturns\sTCL_OK,\swithout\sdetecting\sthat\san\soverflow\shappened.\r\n\r\nI\sagree\swith\syou\sthat\susage\sof\soverflow\strapping\sis\sbad\s....\sin\sproduction\scode.\sBut\sit's\suseful\sfor\sfinding\sbugs\sotherwise\sdifficult\sto\sdetect,\sas\sproven\sin\sthis\sexample:\sWhenever\san\soverflow\soccurs\sduring\smultiplication\sand\sthis\soverflow\sis\snot\sdetected,\sit\smight\slead\sto\sa\swrong\sanswer\swithout\sany\sindication\sthat\sit\shappened.\sThat's\swhy\sa\s-ftrapv\sbuild\sis\sincluded\sin\sour\sbuild\sautomation.\sIt\sshould\snever\sbe\sused\sin\sproduction\sbuilds.\r\n\r\nMy\srecommendation\swould\sbe\sto\suse\sthe\sfunction\sstrtoll().\sIt's\snot\sideal,\sbecause\syou\sneed\sto\scheck\sthe\soverflow\ssituation\susing\serrno\s(or\s-\smayby\s-\sjust\sby\susing\s*endptr),\sbut\sit's\sbetter\sthan\susing\sthis\s(buggy)\s_str2wideInt().\sBut\s...\sI'll\sleave\sthe\ssolution\sto\syou.\r\n\r\n\r\nA\s"knownBug"\stestcase\sis\s[a601eda829827c4c|here],\snow\scommitted\sto\sthe\stip-688\sbranch.\sWe\sdon't\sneed\sto\sstop\sthe\sVoting:\sI'm\ssure\sthis\sbug\scan\sbe\sfixed\s(if\syou\sdon't\sdo\sit,\sI\swill)\r\n\r\nThanks!
J login jan.nijtmans
J mimetype text/x-fossil-wiki
J resolution None
J severity Severe
J status Open
K 1f40aa83c552f597c7aa2e01c7a3a5a2a3fe7c1c
U jan.nijtmans
Z 78c492bc8754fe4289405576c48b6323