Skip to content

Commit

Permalink
Check for undefined outputs in cellfun and arrayfun (bug #66642).
Browse files Browse the repository at this point in the history
* cellfun.cc (Fcellfun, Farrayfun): Check for undefined outputs after each
function call invoked by cellfun or arrayfun.
  • Loading branch information
Fernando Alvarruiz committed Jan 8, 2025
1 parent f9543e2 commit 50cad04
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions libinterp/corefcn/cellfun.cc
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,8 @@ v = cellfun (@@det, C); # 40% faster

retv[j] = val.resize (fdims);
}
else
error ("cellfun: function returned fewer than nargout values");
}
}
else
Expand All @@ -609,6 +611,8 @@ v = cellfun (@@det, C); # 40% faster
idx_type, idx_list, val);
}
}
else
error ("cellfun: function returned fewer than nargout values");
}
}
}
Expand Down Expand Up @@ -661,7 +665,11 @@ v = cellfun (@@det, C); # 40% faster
have_some_output = true;

for (int j = 0; j < num_to_copy; j++)
results[j](count) = tmp(j);
{
if (! tmp(j).is_defined ())
error ("cellfun: function returned fewer than nargout values");
results[j](count) = tmp(j);
}
}
}

Expand Down Expand Up @@ -1332,6 +1340,8 @@ arrayfun (@@str2num, [1234],
error_with_id ("Octave:invalid-fun-call",
"arrayfun: all values must be scalars when UniformOutput = true");
}
else
error ("arrayfun: function returned fewer than nargout values");
}
}
else
Expand All @@ -1355,6 +1365,8 @@ arrayfun (@@str2num, [1234],
"arrayfun: all values must be scalars when UniformOutput = true");
}
}
else
error ("arrayfun: function returned fewer than nargout values");
}
}
}
Expand Down Expand Up @@ -1414,7 +1426,11 @@ arrayfun (@@str2num, [1234],
have_some_output = true;

for (int j = 0; j < num_to_copy; j++)
results[j](count) = tmp(j);
{
if (! tmp(j).is_defined ())
error ("arrayfun: function returned fewer than nargout values");
results[j](count) = tmp(j);
}
}
}

Expand Down

0 comments on commit 50cad04

Please sign in to comment.