bugGNU Octave - Bugs: bug #67650, "logspace (-Inf + 1i, Inf +...

 
 

bug #67650: "logspace (-Inf + 1i, Inf + 1i, 3)" crashes

Submitter:  Dmitri A. Sergatskov <dasergatskov>
Submitted:  Thu 30 Oct 2025 12:28:20 PM UTC
   
 
Category:  Octave Function Severity:  4 - Important
Priority:  5 - Normal Item Group:  Segfault, Bus Error, etc.
Status:  None Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Post a Comment

Add a New Comment Rich Markup
   

Discussion

Fri 31 Oct 2025 11:09:27 AM UTC, comment #5: 

Anyway, I have tried:

diff -r 54882a221d01 libinterp/corefcn/xpow.cc
--- a/libinterp/corefcn/xpow.cc Fri Oct 31 09:47:20 2025 +0100
+++ b/libinterp/corefcn/xpow.cc Fri Oct 31 07:07:09 2025 -0400
@@ -721,13 +721,12 @@
   octave_idx_type nc = b.cols ();

   ComplexMatrix result (nr, nc);
-  Complex acplx (a);

   for (octave_idx_type j = 0; j < nc; j++)
     for (octave_idx_type i = 0; i < nr; i++)
       {
         octave_quit ();
-        result(i, j) = std::pow (acplx, b(i, j));
+        result(i, j) = std::pow (a, b(i, j));
       }

   return result;
@@ -2126,13 +2125,12 @@
   octave_idx_type nc = b.cols ();

   FloatComplexMatrix result (nr, nc);
-  FloatComplex acplx (a);

   for (octave_idx_type j = 0; j < nc; j++)
     for (octave_idx_type i = 0; i < nr; i++)
       {
         octave_quit ();
-        result(i, j) = std::pow (acplx, b(i, j));
+        result(i, j) = std::pow (a, b(i, j));
       }

   return result;


And it does not change a thing (for better or for worse)...
???

Dmitri.
--


Dmitri A. Sergatskov <dasergatskov>
Fri 31 Oct 2025 03:10:49 AM UTC, comment #4: 

It could be related, why do we cast real "a" to complex in
"elem_xpow(double a, const ComplexMatrix& b)", and  "elem_xpow(float a, const FloatComplexMatrix& b)"
?

Dmitri.
--


Dmitri A. Sergatskov <dasergatskov>
Thu 30 Oct 2025 03:07:59 PM UTC, comment #3: 


comment #2:

> Also I think the crashed cased by Fedora enabling "_GLIBCXX_ASSERTIONS", not sure if Ubuntu does the same.


You're correct.  I added -D_GLIBCXX_ASSERTIONS to CPPFLAGS and now my copy aborts in the same manner.

Rik <rik5>
Group administrator
Thu 30 Oct 2025 02:10:47 PM UTC, comment #2: 

Again this is only when compiled with "-O0", "-Og" and higher it runs fine. Since I normally do not use "-O0" often, I do not know if this is a new thing or it has been this way for a while.

Also I think the crashed cased by Fedora enabling "_GLIBCXX_ASSERTIONS", not sure if Ubuntu does the same.

Since it is compiler-dependent crash may be we should make xpow.cc more robust? I was thinking short-circuit std::pow when complex imput has any NaN to NaN+NaNi?

(this way std::pow never see any NaNs)

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Thu 30 Oct 2025 02:00:52 PM UTC, comment #1: 

Changing Severity to Important.  The interpreter should not crash, even for nonsensical input.  FWIW, gcc (Ubuntu 11.4.0-1ubuntu1~22.04.2) 11.4.0 does complete the calculation.

logspace (-Inf + 1i, Inf + 1i, 3)
ans =

        0 +      0i      NaN +    NaNi     -Inf +    Infi


Can someone with access to Matlab check how they handle this?  Do they perform stricter input validation and refuse to create the range?  Or do they create a range of all NaNs?  Or something else?

Since this is an m-file, it would be very easy to add a check for isfinite() on each endpoint.


Rik <rik5>
Group administrator
Thu 30 Oct 2025 12:28:20 PM UTC, original submission:  

When compiled with recent compilers (clang 21.1.3 /gcc 15.2.1)
with optimization disables (-O0), Octave crashes:

octave:1> logspace (-Inf + 1i, Inf + 1i, 3)
/usr/bin/../lib/gcc/x86_64-redhat-linux/15/../../../../include/c++/15/complex:1041: complex<_Tp> std::polar(const _Tp &, const _Tp &) [_Tp = double]: Assertion '__rho >= 0' failed.
fatal: caught signal Aborted -- stopping myself...
Aborted                    (core dumped) ./run-octave


Coredump:

#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007f6bbee80493 in __pthread_kill_internal (threadid=<optimized out>, signo=6) at pthread_kill.c:89
#2  0x00007f6bbee2618e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007f6bbee0d6d0 in __GI_abort () at abort.c:77
#4  0x00007f6bbf00b084 in std::__glibcxx_assert_fail (file=<optimized out>, line=<optimized out>, function=<optimized out>, condition=<optimized out>)
    at ../../../../../libstdc++-v3/src/c++11/assert_fail.cc:41
#5  0x00007f6bc2c3a12a in std::polar<double> (__rho=@0x7ffc9ac5adb8: nan(0x8000000000000), __theta=@0x7ffc9ac5adb0: 2.3025850929940459)
    at /usr/bin/../lib/gcc/x86_64-redhat-linux/15/../../../../include/c++/15/complex:1041
#6  0x00007f6bc2c39b35 in std::pow<double> (__x=@0x7ffc9ac5ae90: 10, __y=...)
    at /usr/bin/../lib/gcc/x86_64-redhat-linux/15/../../../../include/c++/15/complex:1413
#7  0x00007f6bc2cc0b21 in octave::elem_xpow (a=10, b=...) at ../libinterp/corefcn/xpow.cc:1189
#8  0x00007f6bc21f36c2 in octave::oct_binop_el_pow (a1=..., a2=...) at ../libinterp/operators/op-s-cm.cc:89
#9  0x00007f6bc2582c9e in octave::binary_op (ti=..., op=octave_value::op_el_pow, v1=..., v2=...) at ../libinterp/octave-value/ov.cc:2642
#10 0x00007f6bc2618137 in octave::tree_binary_expression::evaluate (this=0x1eb7b7a0, tw=...) at ../libinterp/parse-tree/pt-binop.cc:98
#11 0x00007f6bc2614c32 in octave::tree_simple_assignment::evaluate (this=0x1eb6cb30, tw=...) at ../libinterp/parse-tree/pt-assign.cc:97
#12 0x00007f6bc2630cbe in octave::tree_evaluator::visit_statement (this=0x1de1f200, stmt=...) at ../libinterp/parse-tree/pt-eval.cc:4080
#13 0x00007f6bc265f741 in octave::tree_statement::accept (this=0x1e774c10, tw=...) at ../libinterp/parse-tree/pt-stmt.h:126
#14 0x00007f6bc26312e1 in octave::tree_evaluator::visit_statement_list (this=0x1de1f200, lst=...) at ../libinterp/parse-tree/pt-eval.cc:4165
#15 0x00007f6bc23d9411 in octave::tree_statement_list::accept (this=0x1ea39c40, tw=...) at ../libinterp/parse-tree/pt-stmt.h:232
#16 0x00007f6bc262fb17 in octave::tree_evaluator::execute_user_function (this=0x1de1f200, user_function=..., nargout=0, xargs=...)
    at ../libinterp/parse-tree/pt-eval.cc:3806
#17 0x00007f6bc25646f6 in octave_user_function::execute (this=0x1eb7ccc0, tw=..., nargout=0, args=...) at ../libinterp/octave-value/ov-usr-fcn.cc:574
#18 0x00007f6bc2564625 in octave_user_function::call (this=0x1eb7ccc0, tw=..., nargout=0, args=...) at ../libinterp/octave-value/ov-usr-fcn.cc:567
#19 0x00007f6bc265170e in octave::tree_index_expression::evaluate_n (this=0x1eb352a0, tw=..., nargout=0) at ../libinterp/parse-tree/pt-idx.cc:523
#20 0x00007f6bc2654970 in octave::tree_index_expression::evaluate (this=0x1eb352a0, tw=..., nargout=0) at ../libinterp/parse-tree/pt-idx.h:108
#21 0x00007f6bc2630cbe in octave::tree_evaluator::visit_statement (this=0x1de1f200, stmt=...) at ../libinterp/parse-tree/pt-eval.cc:4080
#22 0x00007f6bc265f741 in octave::tree_statement::accept (this=0x1e9d3dd0, tw=...) at ../libinterp/parse-tree/pt-stmt.h:126
#23 0x00007f6bc26312e1 in octave::tree_evaluator::visit_statement_list (this=0x1de1f200, lst=...) at ../libinterp/parse-tree/pt-eval.cc:4165
#24 0x00007f6bc23d9411 in octave::tree_statement_list::accept (this=0x1e84e230, tw=...) at ../libinterp/parse-tree/pt-stmt.h:232
#25 0x00007f6bc2621924 in octave::tree_evaluator::eval (this=0x1de1f200,
    stmt_list=std::shared_ptr<octave::tree_statement_list> (use count 2, weak count 0) = {...}, interactive=true)
    at ../libinterp/parse-tree/pt-eval.cc:1006
#26 0x00007f6bc26222ca in octave::tree_evaluator::repl (this=0x1de1f200) at ../libinterp/parse-tree/pt-eval.cc:823
#27 0x00007f6bc2a98330 in octave::interpreter::main_loop (this=0x1de1f110) at ../libinterp/corefcn/interpreter.cc:1374
#28 0x00007f6bc2a96d22 in octave::interpreter::execute (this=0x1de1f110) at ../libinterp/corefcn/interpreter.cc:904
#29 0x00007f6bc206d3d3 in octave::cli_application::execute (this=0x7ffc9ac5d230) at ../libinterp/octave.cc:451
#30 0x0000000000400680 in main (argc=8, argv=0x7ffc9ac5d5d8) at ../src/main-cli.cc:150


Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>

 

Attached Files

This item currently has no attached files.

(Note: upload size limit is set to 16MiB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

 

Dependencies

This item does not depend on any other items.

No items depend on this one.

 

Mail Notification Carbon-Copy List

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by dasergatskov (Submitted the item)
  •  

    Votes

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    History

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2025-10-30 rik5 Severity3 - Normal 4 - Important

    Back to the top

    Powered by Savane 3.16.
    Corresponding source code