Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2011-04

Possibly bug spotted in scanner.pas

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Skybuck Flying
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.

Reply by email

Florian Klaempfl
to Skybuck Flying
Skybuck Flying wrote
The code typecasts this 9 byte record towards an 8 byte qword

This wouldn't work and cause a compiler error.

and then takes the first byte from that and type casts it to a char.

The cast tconstexprint -> qword is overloaded.

Reply by email