[Tcsh] Is dolet (@) prone to undefined behavior upon overflow? (Possible overflow issue.)

Matheus Garcia tateusg at hotmail.com
Thu May 2 00:18:15 UTC 2024


Good morning/afternoon/evening. I noticed putn1 breaks the conversion if the last bit is set.

On my machine (an ARM-based cellphone)
@ calc = ( 1 << 63 )
raises a "@: Badly formed number." error. I inspected why's that, and turns out the conversion yields a '(' (left parenthesis) character.

I can't tell for sure if the program is careful on overflow. I can mostly tell it isn't, since none of the variables are unsigned, and there doesn't seem to exist any checks on overflow.

Changing putn1's argument to unsigned remedied the issue.

I'd appreciate for feedbacks on other machines and systems. Note dolet and its counterparts are typed as tcsh_number_t, which, depending on the machine, may be a long or long long type. If
@ calc = ( 1 << 63 )
doesn't raise an error, you may need a larger second operand; else, you're lucky enough for it not to cause an error.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.astron.com/pipermail/tcsh/attachments/20240502/d4386362/attachment.htm>


More information about the Tcsh mailing list