Loading ...
Sorry, an error occurred while loading the content.

1749RE: [jasspa] Bug in meAtoi -- leading zeros

Expand Messages
  • Phillips, Steven
    Dec 20, 2005
    • 0 Attachment
      Changing meAtoi to not handle C style base numeric notation would most
      definitely break a lot of things - see me.emf or grep for '0x' in the
      macros directory.

      The hex notation is used a lot as any numbers used for a bit based flag
      are far more readable in hex. The octal form is certainly used very
      rarely (the only place I can think of where it is used is with routines
      than manipulate the $buffer-fmod variable on unix) so removing support
      for octal would have less impact, but by using strtol ME is using a
      standard numerical form understood by any C/C++ programmer. For this
      reason I am reluctant to change it.

      Steve

      > -----Original Message-----
      > From: jasspa@yahoogroups.com [mailto:jasspa@yahoogroups.com] On Behalf
      Of
      > Thomas Hundt
      > Sent: Monday, December 19, 2005 7:18 PM
      > To: JASSPA MicroEmacs Mailing List (W)
      > Subject: [jasspa] Bug in meAtoi -- leading zeros
      >
      > From what I can see there is a bug in the atoi routine used.
      >
      > I first noticed this when I was trying to remove leading zeroes from
      > part of the ascii-time variable:
      >
      > define-macro test
      > set-variable #l1 "09"
      > insert-string #l1
      > insert-string " -> "
      > set-variable #l1 &add #l1 0 ; "09" -> "9"
      > insert-string #l1
      > newline
      > !emacro
      >
      > The output of this is
      > 09 -> 0
      > when it should really be
      > 9 -> 9
      >
      > If I change the set-variable to "9", it comes out
      > 9 -> 9
      >
      > I tracked down the function, it ends up being in eval.c
      > case UFADD: return meItoa(meAtoi(arg1) + meAtoi(arg2));
      >
      > in eextrn.h it is defined
      > #define meAtoi(s) strtol((char *)(s),(char **)NULL,0)
      > and the 0 here is the base, and is a special value meaning, interpret
      > strings beginning with 0x as hex, and strings beginning with 0 as
      octal.
      > Which is why my "09" comes out as zero: 9 is undefined in octal.
      >
      > Sure enough, if I change my input string to "07", I get
      > 07 -> 7
      >
      > So, my workaround is going to be to prepend a "1" to make it a decimal
      > 1xx number and then subtract off the 100:
      >
      > set-variable #l1 &sub &cat "1" #l1 100 ; "09" -> "9"
      >
      > What I really want to do is fix the base to be, e.g., 10, but would
      that
      > break other things? I don't know.
      >
      >
      >
      >
      > ------------------------ Yahoo! Groups Sponsor
      >
      >
      ________________________________________________________________________
      __
      >
      > This is an unmoderated list. JASSPA is not responsible for the content
      of
      > any material posted to this list.
      >
      > To unsubscribe, send a mail message to
      >
      > mailto:jasspa-unsubscribe@yahoogroups.com
      >
      > or visit http://groups.yahoo.com/group/jasspa and
      > modify your account settings manually.
      >
      >
      >
      > Yahoo! Groups Links
      >
      >
      >
      >
    • Show all 4 messages in this topic