Skip to content

Commit

Permalink
Merge pull request #62 from Goddard-Fortran-Ecosystem/hotfix/#61-segf…
Browse files Browse the repository at this point in the history
…ault-on-extra-args

Fixes #61 - segfault for unprocessed arguments
  • Loading branch information
tclune authored Dec 20, 2019
2 parents 0aeda75 + a622769 commit 5007224
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 35 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.8)

project (FARGPARSE
VERSION 0.9.1
VERSION 0.9.2
LANGUAGES Fortran)

# Most users of this software do not (should not?) have permissions to
Expand All @@ -27,16 +27,16 @@ endif()

find_package (PFUNIT 4.0.1 QUIET)
if (PFUNIT_FOUND)
project (GFTL-TEST
VERSION ${GFTL_VERSION}
project (FARGPARSE_-TEST
VERSION ${FARGPARSE_VERSION}
LANGUAGES Fortran
)

set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${GFTL_SOURCE_DIR}/cmake_utils")
include (${CMAKE_Fortran_COMPILER_ID} RESULT_VARIABLE found)

enable_testing()
if (NOT TARGET (tests))
if (NOT TARGET tests)
add_custom_target(tests COMMAND ${CMAKE_CTEST_COMMAND})
endif ()

Expand Down
17 changes: 12 additions & 5 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
0.9.0 2019-09-04
- Updated to use pFUnit 4.0
# Change log

## [0.9.2] - 2019-12-19
- Bug fix for extra arguments.
- Updated gFTL to latest

## [0.9.1] - 2019-11-08
- Workaround for compiler hang in ifort 19.0.3
- Updated gFTL for memory leak workaround in ifort 18

## [0.9.0] - 2019-09-04
- Updated to use pFUnit 4.0

0.9.1 2019-11-08
- Workaround for compiler hang in ifort 19.0.3
- Updated gFTL for memory leak workaround in ifort 18

2 changes: 1 addition & 1 deletion extern/gFTL
2 changes: 1 addition & 1 deletion extern/gFTL-shared
Submodule gFTL-shared updated 1 files
+1 −1 extern/gFTL
54 changes: 30 additions & 24 deletions src/ArgParser.F90
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,21 @@ function parse_args_args(this, arguments, unused, unprocessed) result(option_val

else ! is positional
ith = ith + 1
act => this%positionals%at(ith)
select case (act%get_type())
case ('string')
call option_values%insert(act%get_destination(), argument)
case ('integer')
read(argument,*) arg_value_int
call option_values%insert(act%get_destination(), arg_value_int)
case ('real')
read(argument,*) arg_value_real
call option_values%insert(act%get_destination(), arg_value_real)
end select
if (present(unprocessed)) call unprocessed%push_back(argument)
if (ith <= this%positionals%size()) then
act => this%positionals%at(ith)
select case (act%get_type())
case ('string')
call option_values%insert(act%get_destination(), argument)
case ('integer')
read(argument,*) arg_value_int
call option_values%insert(act%get_destination(), arg_value_int)
case ('real')
read(argument,*) arg_value_real
call option_values%insert(act%get_destination(), arg_value_real)
end select
else
if (present(unprocessed)) call unprocessed%push_back(argument)
end if
end if


Expand Down Expand Up @@ -327,18 +330,21 @@ subroutine parse_args_kludge_args(this, option_values, arguments, unused, unproc

else ! is positional
ith = ith + 1
act => this%positionals%at(ith)
select case (act%get_type())
case ('string')
call option_values%insert(act%get_destination(), argument)
case ('integer')
read(argument,*) arg_value_int
call option_values%insert(act%get_destination(), arg_value_int)
case ('real')
read(argument,*) arg_value_real
call option_values%insert(act%get_destination(), arg_value_real)
end select
if (present(unprocessed)) call unprocessed%push_back(argument)
if (ith <= this%positionals%size()) then
act => this%positionals%at(ith)
select case (act%get_type())
case ('string')
call option_values%insert(act%get_destination(), argument)
case ('integer')
read(argument,*) arg_value_int
call option_values%insert(act%get_destination(), arg_value_int)
case ('real')
read(argument,*) arg_value_real
call option_values%insert(act%get_destination(), arg_value_real)
end select
else
if (present(unprocessed)) call unprocessed%push_back(argument)
end if
end if


Expand Down
21 changes: 21 additions & 0 deletions tests/Test_ArgParser.pf
Original file line number Diff line number Diff line change
Expand Up @@ -576,4 +576,25 @@ contains

end subroutine test_pfunit_use_case

! Reproducer for Issue #61
@test
subroutine test_unprocessed_argument
use fp_CommandLineArguments
use fp_String
type (ArgParser) :: p
type (StringVector) :: arguments
type (StringUnlimitedMap) :: options
class(*), pointer :: opt

p = ArgParser()

call p%add_argument('-d', '--debug', '--verbose', action='store_true', &
& help='make output more verbose')

! Crashes before fix
call arguments%push_back('-not-a-valid-argument')
options = p%parse_args(arguments)

end subroutine test_unprocessed_argument

end module Test_ArgParser

0 comments on commit 5007224

Please sign in to comment.