Skip to content

Conversation

@St-Maxwell
Copy link
Member

I found fpm will crash when executing fpm build --show-model, if there are empty source files in project.

After looking into code, I found parse_f_source returns an instance of srcfile_t with its allocatable members uninitialized for empty source files.

! Ignore empty files, returned as FPM_UNIT_UNKNOWN
if (len_trim(file_lines_lower) < 1) return

As a result, in info_srcfile function, an error will occur when printing srcfile_t objects with FPM_UNIT_UNKNOWN type.

So I make it skip for FPM_UNIT_UNKNOWN type.

@LKedward
Copy link
Member

Thanks for spotting this @St-Maxwell - quick question: would deleting the if (len_trim(file_lines_lower) < 1) return line also solve this problem? Then maybe parse_f_source would just allocate zero-length arrays

@St-Maxwell
Copy link
Member Author

@LKedward Thanks for replying. I think it is OK to remove if (len_trim(file_lines_lower) < 1) return and add an extra change to the next statement, because fnv_1a requires a non-zero-length arrays. If this change is preferred, I will update my commit.

from

! Ignore empty files, returned as FPM_UNIT_UNKNOWN
if (len_trim(file_lines_lower) < 1) return

f_source%digest = fnv_1a(file_lines)

to

! Ignore empty files, returned as FPM_UNIT_UNKNOWN
!if (len_trim(file_lines_lower) < 1) return

if (len_trim(file_lines_lower) >= 1) f_source%digest = fnv_1a(file_lines)

@LKedward
Copy link
Member

Thanks okay yes I think this would be preferred; my reasoning for this is to ensure that parse_f_source always returns the 'same' thing (ie all components allocated), so that we don't need to repeatedly code special statements everywhere else in the code.

Copy link
Member

@LKedward LKedward left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for this fix @St-Maxwell. All looks good to me 👍

@LKedward LKedward merged commit 67132c4 into fortran-lang:main Apr 20, 2022
@awvwgk awvwgk added this to the v0.6.0 milestone Apr 22, 2022
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.

3 participants