[fpc-devel] Possibly bug spotted in scanner.pas

Skybuck Flying skybuck2000 at hotmail.com
Thu Apr 7 03:52:48 CEST 2011


Around line 1120:
                        else if is_char(constdef) then
                         begin
                          read_factor:=char(qword(value.valueord));
                          factorType:= [ctetString];
                         end

valueord seems to be type casted towards an int64.

The actual field is defined as follows in symsym.pas:

       tconstvalue = record
         case integer of
         0: (valueord : tconstexprint);
         1: (valueordptr : tconstptruint);
         2: (valueptr : pointer; len : longint);
       end;

valueord is defined as follows in constexp.pas:

type  Tconstexprint=record
        overflow:boolean;
        case signed:boolean of
          false:
            (uvalue:qword);
          true:
            (svalue:int64);
      end;

In other words the last record is 9 bytes, the first byte is actually an 
overflow byte.

The code typecasts this 9 byte record towards an 8 byte qword and then takes 
the first byte from that and type casts it to a char.

(Which will probably be unsafe if char is changed to wide char or perhaps 
not... time will tell....)

So to me it seems the "overflow boolean" is being assigned towards the 
"read_factor" variable.

If that was the intent then it's probably ok... but else it might be a bug ?

If that was the intent then why not write:

read_factor := char(value.valueord.overflow)

Also my assumption that a boolean is only 1 byte might be wrong ;) but for 
now I will assume it's 1 byte ;)

To me the code looks a bit suspicious but it might be nothing...

Bye,
  Skybuck.
























More information about the fpc-devel mailing list