• Re: Weird code crash

    From Robert Riches@21:1/5 to The Natural Philosopher on Fri Sep 15 00:40:18 2023
    On 2023-09-14, The Natural Philosopher <tnp@invalid.invalid> wrote:
    On 14/09/2023 16:29, Ralf Fassel wrote:
    * The Natural Philosopher <tnp@invalid.invalid>
    | One possibility is that it is opening and reading a file at the
    | precise time another process is writing it...in both cases the read
    | and write
    | operations are atomic and done with C code.

    | READ
    | ====
    | fp=fopen(fullname, "r");
    | len=fread(filbuf,1,255,fp); // read entire file

    Check for fp != NULL is missing here in this example code before
    fread(). If this also in the production version, it might be a problem
    if the file is not accessible for any reason.

    R'
    Ralf, I already put that in this morning, re compiled the code and after
    an hour, it crashed again.

    The filename is built by scanning a directory so the filename must exist.

    Maybe not applicable in this situation, but if something deleted
    the file between the time of the scan and the time of the fopen
    call, it might/would not exist.

    --
    Robert Riches
    spamtrap42@jacob21819.net
    (Yes, that is one of my email addresses.)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to Robert Riches on Fri Sep 15 10:23:40 2023
    On 15/09/2023 01:40, Robert Riches wrote:
    On 2023-09-14, The Natural Philosopher <tnp@invalid.invalid> wrote:
    On 14/09/2023 16:29, Ralf Fassel wrote:
    * The Natural Philosopher <tnp@invalid.invalid>
    | One possibility is that it is opening and reading a file at the
    | precise time another process is writing it...in both cases the read
    | and write
    | operations are atomic and done with C code.

    | READ
    | ====
    | fp=fopen(fullname, "r");
    | len=fread(filbuf,1,255,fp); // read entire file

    Check for fp != NULL is missing here in this example code before
    fread(). If this also in the production version, it might be a problem
    if the file is not accessible for any reason.

    R'
    Ralf, I already put that in this morning, re compiled the code and after
    an hour, it crashed again.

    The filename is built by scanning a directory so the filename must exist.

    Maybe not applicable in this situation, but if something deleted
    the file between the time of the scan and the time of the fopen
    call, it might/would not exist.


    Exactly. That is a possibility, which I have now covered. It made no difference.

    In practice the write code that *replaces* the file is very simple. It is fopen( "w") immediately followed by
    fwrite()

    without knowing the exact code involved with the fopen("w"); I cant say
    if that actually deletes the file and creates a new one, or merely
    truncates it to zero length, or indeed just opens it and trips the
    length *after* the new data is written..



    --
    WOKE is an acronym... Without Originality, Knowledge or Education.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)