Skip to content

Conversation

@jodavies
Copy link
Collaborator

This fixes #668 .

The second commit takes care of the new test case failing under the coverage runs.

@coveralls
Copy link

coveralls commented Sep 25, 2025

Coverage Status

coverage: 54.382% (+0.008%) from 54.374%
when pulling 22d8c83 on jodavies:setups-file
into 9828301 on form-dev:master.

@tueda
Copy link
Collaborator

tueda commented Sep 26, 2025

Assuming Linux, a truncated file can be tested as

*--#[ Issue668 :
* Check error message for invalid setup parameter:
#system printf "#:x">temp.frm
#system `FORM' temp.frm
.end
#require linux?
assert runtime_error?("Setups in .frm file: Keyword not recognized: x")
*--#] Issue668 : 

@jodavies
Copy link
Collaborator Author

Nice trick. Looks like we need to skip it for parform in addition:

ParFORM 5.0.0-beta.1 (Sep 29 2025, v5.0.0-beta.1-232-g6e0c402) 3 workers  Run: Mon Sep 29 08:03:08 2025
    * Check error message for invalid setup parameter:
    * In this case, an unexpected end-of-file as in the original report.
    #system printf "#:x">temp.frm
    #system `FORM' temp.frm
1.frm Line 5 ==> System call returned with error condition
Program terminating in process 0 at 1.frm Line 1 --> 
Terminate called from pre.c:4280 (DoSystem)
  0.00 sec + 0.00 sec: 0.00 sec out of 0.00 sec

Also add tests of the proper error message, for a "normal" file
and in case the file ends unexpectedly. This one doesn't work in
parform.
This otherwise causes problems, apparently only when compiling with
--enable-coverage (gcc 13.3).
@jodavies jodavies merged commit 545e427 into form-dev:master Sep 30, 2025
84 checks passed
@tueda
Copy link
Collaborator

tueda commented Sep 30, 2025

FYI: here is an equivalent example that leads to a Valgrind error unless hi is reduced by 1:

#include <stdio.h>
#include <string.h>

const char *setupparameters[] = {
    "abc",
    "def",
};

const char *GetSetupPar(const char *s)
{
    int hi, med, lo, i;
    lo = 0;
    hi = sizeof(setupparameters)/sizeof(setupparameters[0]);
    do {
        med = ( hi + lo ) / 2;
        i = strcmp(s,setupparameters[med]);
        if ( i == 0 ) return(*(setupparameters+med));
        if ( i < 0 ) hi = med-1;
        else         lo = med+1;
    } while ( hi >= lo );
    return(0);
}

int main()
{
    const char *name = "x";
    const char *param = GetSetupPar(name);
    if ( param ) {
        printf("Found: %s\n",param);
    }
    else {
        printf("Not found\n");
    }
    return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Buffer overrun in setfile.c if no newline before file end

3 participants