Forum > General

Free Pascal produces runtime error 107

(1/1)

mggm:
...which is not listed here: http://www.freepascal.org/docs-html/user/userap4.html . I thought this document was meant to be exhaustive, or was I wrong?

Here is what I did:
a) Compiled a simple http://pastebin.com/Qf4pRNN6 piece of code with no compiler options - simply fpc wont.pas
b) Used the compiled code to produce file wont.dat (inserted a 0 on standard input)
c) Screwed up the produced file
d) Tried to use the compiled code to open the screwed up file wont.dat (inserted a 1 on standard input).
e) Received:
Runtime error 107 at $00000000004002CD
  $00000000004002CD
  $0000000000400180

EDIT: I've run into a yet another thingy I can't understand while playing with the sample.

I slighlty modified the code: http://pastebin.com/vpq0QeEz Running the code (it does not crash with the {$I-} switch now) and commenting the writelns in and out showed that IOResult is set to 0! But removing the {$I-} switch immediately produces the above runtime error. I find this weird, becouse if I understand the documentation of the switch http://www.freepascal.org/docs-html/prog/progsu38.html#x45-440001.2.38 , the program with {$I-} should have IOResult set to something other then 0 if and only if the same program in the same conditions, but with {$I+} would crash. Yet there happenes the opposite: the program with {$I+} crashes, but with {$I-} reports no errors with IOResult. Why so?

BigChimp:
Yes, it's meant to be exhaustive for current stable FPC (i.e. 2.6.4).

In any case, you could go grep through the source code to find the exact error number... (but if 107 exists on FPC 2.6.4 then it is a bug in the documentation, yes)

Please always specify what FPC/Lazarus version you are using, and operating system (see first link in my signature). Thanks.

marcov:
It seems to be the write(enum) functionality. If the conversion fails then this runtime error is raised.

mggm:
Sorry.

So, I'm on Linux Mint 16, Cinnamon. Well, it's FPC 2.6.2 , so maybe that's the reason...

Anyway, I found something with grep. It's file /rtl/inc/sstrings.inc, lines 536-543. They read:

procedure fpc_shortstr_enum(ordinal,len:sizeint;typinfo,ord2strindex:pointer;out s:shortstring);[public,alias:'FPC_SHORTSTR_ENUM'];compilerproc;
var
  res: longint;
begin
  res:=fpc_shortstr_enum_intern(ordinal,len,typinfo,ord2strindex,s);
  if (res<>0) then
    runerror(107);
end;

Edit: @marcov, it seems it is how you say. But if so, why {$I-} prevents the program from crashing?

Well, the program crashes because it can't handle the enum correctly. But {$I-} should prevent it from crashing only if it couldn't read the data correctly. But no errors araised there, since IOResult continues to be set to 0!

Edit2: Ahh, I get it. http://pastebin.com/DLxVpyfs Now the program prints out nicely 107. The error araises on an attempt to write g, not to read the file . Anyway, IOResult code 107 again is not documented: http://www.freepascal.org/docs-html/rtl/system/ioresult.html

Seems I'll have to compile & run the program on an up-to-date fpc version.

Navigation

[0] Message Index

Go to full version