Skip to content

Commit f5bb9df

Browse files
committed
fixed an issue where some error messages could try to print a name that wasn't allocated
Fixes #491
1 parent 8ff8876 commit f5bb9df

File tree

1 file changed

+84
-30
lines changed

1 file changed

+84
-30
lines changed

src/json_value_module.F90

Lines changed: 84 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8141,8 +8141,13 @@ subroutine json_get_integer(json, me, value)
81418141
value = me%int_value
81428142
else
81438143
if (json%strict_type_checking) then
8144-
call json%throw_exception('Error in json_get_integer:'//&
8145-
' Unable to resolve value to integer: '//me%name)
8144+
if (allocated(me%name)) then
8145+
call json%throw_exception('Error in json_get_integer:'//&
8146+
' Unable to resolve value to integer: '//me%name)
8147+
else
8148+
call json%throw_exception('Error in json_get_integer:'//&
8149+
' Unable to resolve value to integer')
8150+
end if
81468151
else
81478152
!type conversions
81488153
select case(me%var_type)
@@ -8158,13 +8163,24 @@ subroutine json_get_integer(json, me, value)
81588163
call string_to_integer(me%str_value,value,status_ok)
81598164
if (.not. status_ok) then
81608165
value = 0_IK
8161-
call json%throw_exception('Error in json_get_integer:'//&
8162-
' Unable to convert string value to integer: me.'//&
8163-
me%name//' = '//trim(me%str_value))
8166+
if (allocated(me%name)) then
8167+
call json%throw_exception('Error in json_get_integer:'//&
8168+
' Unable to convert string value to integer: '//&
8169+
me%name//' = '//trim(me%str_value))
8170+
else
8171+
call json%throw_exception('Error in json_get_integer:'//&
8172+
' Unable to convert string value to integer: '//&
8173+
trim(me%str_value))
8174+
end if
81648175
end if
81658176
case default
8166-
call json%throw_exception('Error in json_get_integer:'//&
8167-
' Unable to resolve value to integer: '//me%name)
8177+
if (allocated(me%name)) then
8178+
call json%throw_exception('Error in json_get_integer:'//&
8179+
' Unable to resolve value to integer: '//me%name)
8180+
else
8181+
call json%throw_exception('Error in json_get_integer:'//&
8182+
' Unable to resolve value to integer')
8183+
end if
81688184
end select
81698185
end if
81708186
end if
@@ -8354,8 +8370,13 @@ subroutine json_get_real(json, me, value)
83548370
value = me%dbl_value
83558371
else
83568372
if (json%strict_type_checking) then
8357-
call json%throw_exception('Error in json_get_real:'//&
8358-
' Unable to resolve value to real: '//me%name)
8373+
if (allocated(me%name)) then
8374+
call json%throw_exception('Error in json_get_real:'//&
8375+
' Unable to resolve value to real: '//me%name)
8376+
else
8377+
call json%throw_exception('Error in json_get_real:'//&
8378+
' Unable to resolve value to real')
8379+
end if
83598380
else
83608381
!type conversions
83618382
select case (me%var_type)
@@ -8371,9 +8392,15 @@ subroutine json_get_real(json, me, value)
83718392
call string_to_real(me%str_value,json%use_quiet_nan,value,status_ok)
83728393
if (.not. status_ok) then
83738394
value = 0.0_RK
8374-
call json%throw_exception('Error in json_get_real:'//&
8375-
' Unable to convert string value to real: me.'//&
8376-
me%name//' = '//trim(me%str_value))
8395+
if (allocated(me%name)) then
8396+
call json%throw_exception('Error in json_get_real:'//&
8397+
' Unable to convert string value to real: '//&
8398+
me%name//' = '//trim(me%str_value))
8399+
else
8400+
call json%throw_exception('Error in json_get_real:'//&
8401+
' Unable to convert string value to real: '//&
8402+
trim(me%str_value))
8403+
end if
83778404
end if
83788405
case (json_null)
83798406
if (ieee_support_nan(value) .and. json%null_to_real_mode/=1_IK) then
@@ -8388,13 +8415,22 @@ subroutine json_get_real(json, me, value)
83888415
value = 0.0_RK
83898416
end select
83908417
else
8391-
call json%throw_exception('Error in json_get_real:'//&
8392-
' Cannot convert null to NaN: '//me%name)
8418+
if (allocated(me%name)) then
8419+
call json%throw_exception('Error in json_get_real:'//&
8420+
' Cannot convert null to NaN: '//me%name)
8421+
else
8422+
call json%throw_exception('Error in json_get_real:'//&
8423+
' Cannot convert null to NaN')
8424+
end if
83938425
end if
83948426
case default
8395-
8396-
call json%throw_exception('Error in json_get_real:'//&
8397-
' Unable to resolve value to real: '//me%name)
8427+
if (allocated(me%name)) then
8428+
call json%throw_exception('Error in json_get_real:'//&
8429+
' Unable to resolve value to real: '//me%name)
8430+
else
8431+
call json%throw_exception('Error in json_get_real:'//&
8432+
' Unable to resolve value to real')
8433+
end if
83988434
end select
83998435
end if
84008436
end if
@@ -8844,9 +8880,14 @@ subroutine json_get_logical(json, me, value)
88448880
value = me%log_value
88458881
else
88468882
if (json%strict_type_checking) then
8847-
call json%throw_exception('Error in json_get_logical: '//&
8848-
'Unable to resolve value to logical: '//&
8849-
me%name)
8883+
if (allocated(me%name)) then
8884+
call json%throw_exception('Error in json_get_logical: '//&
8885+
'Unable to resolve value to logical: '//&
8886+
me%name)
8887+
else
8888+
call json%throw_exception('Error in json_get_logical: '//&
8889+
'Unable to resolve value to logical')
8890+
end if
88508891
else
88518892
!type conversions
88528893
select case (me%var_type)
@@ -8857,9 +8898,14 @@ subroutine json_get_logical(json, me, value)
88578898
case (json_string)
88588899
value = (me%str_value == true_str)
88598900
case default
8860-
call json%throw_exception('Error in json_get_logical: '//&
8861-
'Unable to resolve value to logical: '//&
8862-
me%name)
8901+
if (allocated(me%name)) then
8902+
call json%throw_exception('Error in json_get_logical: '//&
8903+
'Unable to resolve value to logical: '//&
8904+
me%name)
8905+
else
8906+
call json%throw_exception('Error in json_get_logical: '//&
8907+
'Unable to resolve value to logical')
8908+
end if
88638909
end select
88648910
end if
88658911
end if
@@ -9046,8 +9092,13 @@ subroutine json_get_string(json, me, value)
90469092
else
90479093

90489094
if (json%strict_type_checking) then
9049-
call json%throw_exception('Error in json_get_string:'//&
9050-
' Unable to resolve value to string: '//me%name)
9095+
if (allocated(me%name)) then
9096+
call json%throw_exception('Error in json_get_string:'//&
9097+
' Unable to resolve value to string: '//me%name)
9098+
else
9099+
call json%throw_exception('Error in json_get_string:'//&
9100+
' Unable to resolve value to string')
9101+
end if
90519102
else
90529103

90539104
select case (me%var_type)
@@ -9094,11 +9145,14 @@ subroutine json_get_string(json, me, value)
90949145
value = null_str
90959146

90969147
case default
9097-
9098-
call json%throw_exception('Error in json_get_string: '//&
9099-
'Unable to resolve value to characters: '//&
9100-
me%name)
9101-
9148+
if (allocated(me%name)) then
9149+
call json%throw_exception('Error in json_get_string: '//&
9150+
'Unable to resolve value to characters: '//&
9151+
me%name)
9152+
else
9153+
call json%throw_exception('Error in json_get_string: '//&
9154+
'Unable to resolve value to characters')
9155+
end if
91029156
end select
91039157

91049158
end if

0 commit comments

Comments
 (0)