Skip to content

Commit 3f9ead8

Browse files
author
Andy Stokely
committed
Fix mpas_stream_list_insert bug unlinking head on duplicate insert
Fix bug in mpas_stream_list_insert that could unlink the head node when a duplicate stream was inserted. Moved nullify(stream % next) calls into the relevant conditional blocks to ensure new streams are only linked after passing duplicate checks. Prevents inadvertent modification of the list when duplicate insertions occur.
1 parent b16dd8b commit 3f9ead8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/framework/mpas_stream_list.F

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ subroutine MPAS_stream_list_insert(list, stream, ierr) !{{{
112112
113113
if (present(ierr)) ierr = MPAS_STREAM_LIST_NOERR
114114
115-
nullify(stream % next)
116115
if (.not. associated(list % head)) then
117116
list % head => stream
117+
nullify(stream % next)
118118
else
119119
node => list % head
120120
do while (associated(node))
@@ -125,6 +125,7 @@ subroutine MPAS_stream_list_insert(list, stream, ierr) !{{{
125125
end if
126126
if (.not. associated(node % next)) then
127127
node % next => stream
128+
nullify(stream % next)
128129
exit
129130
end if
130131
node => node % next

0 commit comments

Comments
 (0)