Recent

Author Topic: [SOLVED] When is nil not nil?  (Read 5571 times)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
[SOLVED] When is nil not nil?
« on: March 06, 2014, 03:52:41 pm »
x86 FPC trunk, Lazarus trunk:
I'm feeling fairly stupid, but... here goes:
I had code like this (dbf_dbffile in FPC trunk):
Code: [Select]
procedure TDbfFile.SetFieldData(Column: Integer; DataType: TFieldType;
  Src, Dst: Pointer; NativeFormat: boolean); 
...
var
...
  Len: Integer;
Code: [Select]
          Len := PWord(Src)^;
          if Len > FieldSize then
            Len := FieldSize;

I suspected Src could be an unassigned pointer and changed the code to
Code: [Select]
        if Src = nil then
          Len := 0
        else
        begin
          Len := PWord(Src)^;
          if Len > FieldSize then
            Len := FieldSize;
        end;

Running through the debugger, I break on the first line, if Src = nil.

The debugger shows Src is indeed nil, but when I try to step past, I get a SIGSEGV.

Any ideas?
« Last Edit: March 06, 2014, 04:59:17 pm by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: When is nil not nil?
« Reply #1 on: March 06, 2014, 03:59:05 pm »
Probably a debugger (gdb) problem?
Throw in some writeln()'s to debug it?

Bart

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: When is nil not nil?
« Reply #2 on: March 06, 2014, 04:08:08 pm »
Edit: not solved yet:
I had been testing dbtestframework_gui against MS SQL server under Lazarus debugger.

When I compile & run dbtestframework.pas, the command line version, edit: using the SAME db as previously (instead of a different one that does not support the field type in question... sorry), the test still has errors:
Quote
    00.162  TestDBFExport_VisualFoxPro  Error: EAccessViolation
      Exception:   Access violation
      Source unit:
      Method name:
      Line number: 0

Now going to add some writelns...
« Last Edit: March 06, 2014, 04:14:29 pm by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: [SOLVED] When is nil not nil?
« Reply #3 on: March 06, 2014, 04:59:24 pm »
Interesting. On my Linux x64 system, the second code snippet works fine. It should be running the same tests (same database backend) unless I messed up again.

Throwing in some writelns and recompiling indicates the text mode test program works fine on Windows now, too, so I guess it was the debugger in Lazarus after all....

Thanks.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018