-
Notifications
You must be signed in to change notification settings - Fork 103
fix two unitialized variables found w/ valgrind #662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ module med_merge_mod | |
| use esmFlds , only : med_fldList_findName | ||
| use perf_mod , only : t_startf, t_stopf | ||
| use shr_log_mod , only : shr_log_error | ||
|
|
||
| implicit none | ||
| private | ||
|
|
||
|
|
@@ -128,7 +128,7 @@ subroutine med_merge_auto_multi_fldbuns(coupling_active, FBOut, FBfrac, FBImp, f | |
| call med_fld_GetFldInfo(fldptr, compsrc=compsrc, merge_fields=merge_fields, merge_type=merge_type, merge_fracname=merge_fracname, rc=rc) | ||
| if (chkerr(rc,__LINE__,u_FILE_u)) return | ||
|
|
||
| if (merge_type /= 'unset' .and. merge_field /= 'unset') then | ||
| if (merge_type /= 'unset' .and. merge_fields /= 'unset') then | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with this change - thanks. |
||
| ! If merge_field is a colon delimited string then cycle through every field - otherwise by default nm | ||
| ! will only equal 1 | ||
| num_merge_colon_fields = merge_listGetNum(merge_fields) | ||
|
|
@@ -489,7 +489,7 @@ subroutine med_merge_auto_errcheck(compsrc, fldname_out, field_out, & | |
| write(errmsg,*) trim(subname),' input field ungriddedUbound ',ungriddedUbound_in(1),& | ||
| ' for '//trim(merge_fldname), & | ||
| ' not equal to output field ungriddedUbound ',ungriddedUbound_out,' for '//trim(fldname_out) | ||
|
|
||
| call shr_log_error(errmsg, rc=rc) | ||
| endif | ||
|
|
||
|
|
@@ -647,7 +647,7 @@ subroutine med_merge_field_1D(FBout, fnameout, & | |
| endif | ||
| if (wgtfound) then | ||
| if (lbound(dataPtr,1) /= lbound(wgt,1) .or. ubound(dataPtr,1) /= ubound(wgt,1)) then | ||
|
|
||
| call shr_log_error(trim(subname)//": ERROR wgt wrong size", & | ||
| line=__LINE__, file=u_FILE_u, rc=dbrc) | ||
| return | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with this change, but it makes me wonder if this might be masking a more serious issue. I don't have experience with valgrind, so I'm not sure: does the issue picked up in #661 suggest an actual attempt to reference a field with previously-uninitialized values, or just that valgrind can't guarantee that the data was initialized? If the former, I'm wondering if the real solution is to figure out the code path that has led to the use of a field with uninitialized stdname / shortname? Otherwise, it seems like we might be masking the problem by satisfying valgrind but with non-sensical data. @DeniseWorthen @DusanJovic-NOAA what do you think?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My initial fix was more complicated (partly a result of querying AI for assistance). Those code changes were
The attempt here was to ensure that if a match was not found, lastfld%next would still point to the very last (found) field. But Dusan reported that it did not resolve the issue.
I also don't have valgrind experience, but Dusan provided instructions and I can try to work through a better fix if you have ideas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With Claude's help, I think I understand the problem: When
med_fldList_findNameis called on a currently-empty list, the last line (if (trim(stdname) == trim(lastfld%stdname)) found = .true.) will be working on uninitialized data.Now that I understand that issue, the fix here makes sense to me.