szaghi / FLAP

Fortran command Line Arguments Parser for poor people
150 stars 34 forks source link

Non initialized Error code in parse() procedure #69

Closed victorsndvg closed 7 years ago

victorsndvg commented 7 years ago

Hi @szaghi ,

I think there is a bug (in release mode) using FLAP while parsing CLI multiple times. If I run the code below, the second time that I call parse(error), error value is not initialized from the parse() procedure.

     type(Command_Line_Interface)  :: cli
     integer :: error
     cli%parse(error)
     ...
     cli%free() 
     ...
     cli%parse(error)
     ...
     cli%free() 

I think that there are 2 minor changes to fix this behaviour. First, force a successful error code at the begining of the parse() procedure in this line: https://github.com/szaghi/FLAP/blob/master/src/lib/flap_command_line_interface_t.F90#L519

    if(present(error)) error = 0  ! <- New line
    if (self%is_parsed_) return
    ...

And finally, Set is_parsed_ variable to .false. in the free() procedure.

You can see this changes in my FLAP-fork in this commit : https://github.com/victorsndvg/FLAP/commit/a9c201a46b402b5a9d00a9b2db6a815ead0b3722

Do you think I'm right or there is something that I'm missing?

szaghi commented 7 years ago

Great @victorsndvg , I'll look into it now!

szaghi commented 7 years ago

@victorsndvg You are right! Just patched! Thank you very much. New master will be uploaded soon.

P.S. I think this is the first test of %free method... I have to expand the tests suite...

szaghi commented 7 years ago

@victorsndvg New v1.1.1 pushed. I think your patch is perfect, no other missing issues should be involved, many many thanks!