• Paul Eggert's avatar
    Fix mishandling of symbols that look like numbers · 5bd8cfc1
    Paul Eggert authored
    * src/bignum.c (make_neg_biguint): New function.
    * src/lread.c (read1): Do not mishandle an unquoted symbol
    with name equal to something like "1\0x", i.e., a string
    of numeric form followed by a NUL byte.
    Formerly these symbols were misread as numbers.
    (string_to_number): Change last argument from an integer flag
    to a pointer to the length.  This lets the caller figure out
    how much of the prefix was used.  All callers changed.
    Add a fast path if the integer (sans sign) fits in uintmax_t.
    Update comments and simplify now that bignums are present.
    * src/print.c (print_object): Fix quoting of symbols that look
    like numbers, by relying on string_to_number for the tricky
    cases rather than trying to redo its logic, incorrectly.  For
    example, (read (prin1-to-string '\1e+NaN)) formerly returned
    "1e+NaN", which was wrong: a backslash is needed in the output
    to prevent it from being read as a NaN.  Escape NO_BREAK_SPACE
    too, since lread.c treats it like SPACE.
    * test/src/print-tests.el (print-read-roundtrip):
    Add tests illustrating the abovementioned bugs.
    5bd8cfc1
bignum.c 8.73 KB