Inform - Support - Patches

About Patches  

Compiler  
Library  

DM4 Errata  

Issue C62003

Zcharacter directive problems
Submitted by: Torbjörn Andersson     Appeared in: Compiler 6.20     Fixed in: Compiler 6.30
Problem

The Zcharacter directive can attempt to write values greater than 127 into the alphabet table, which is a two-dimensional array of char. If char is signed, this means that when reading the value back you will get a negative value. This value is then used as array index when writing to other arrays.

The test program I used looked like

  Zcharacter '@`e';   ! E-grave

  [ Main;
      print 36;
  ];

but the actual result of this is compiler-dependent. In fact, you may not see any error at all. In my case, however, it produced a compiler error because it had overwritten the table entry that told it that the character '6' could be part of a numerical constant.

Solution

I assume that changing the type of alphabet[3][27] from "char" to "uchar" in chars.c and header.h will fix the problem.

Update (by Kevin Bracey)

The suggested patch needs one slight addition -- it's not valid to pass an "unsigned char *" pointer to a strcpy, so the little trio of strcpys that initialise the alphabet table either needs casts or to be turned into memcpys:

      strcpy((char *) alphabet[0], "abcdefghijklmnopqrstuvwxyz");
  or  memcpy(alphabet[0], "abcdefghijklmnopqrstuvwxyz", 26);


Last updated 17 April 2013. This web site has not been fully supported since April 2008. Information may be out of date. This page was originally managed by Roger Firth.