Skip to content

Segfault when executing a Tango command, that expects and array, with an empty array as parameter

Hi

When executing a command on a Tango device that expects an array, a segfault will be thrown when an empty array is used as parameter. Seems to affect all array command types.

Sample below showing an empty array failing and a non empty array working as expected.

root@484fb9cd4821:/# evcxr
Welcome to evcxr. For help, type :help
>> :dep tango-client = "0.4.1"
>> use tango_client::{DeviceProxy, CommandData};
>> let mut dev = DeviceProxy::new("sys/tg_test/1")?;
>> let res = dev.command_inout("DevVarCharArray", CommandData::CharArray("some_chars".as_bytes().to_vec()))?;
>> res
CharArray([115, 111, 109, 101, 95, 99, 104, 97, 114, 115])
>>  let res = dev.command_inout("DevVarCharArray", CommandData::CharArray("".as_bytes().to_vec()))?;
Segmentation fault.
   0: evcxr::runtime::Runtime::install_crash_handlers::segfault_handler
   1: <unknown>
   2: cfree
   3: tango_client::proxy::DeviceProxy::command_inout
   4: run_user_code_6
   5: evcxr::runtime::Runtime::run_loop
   6: evcxr::runtime::runtime_hook
   7: evcxr::main
   8: std::sys_common::backtrace::__rust_begin_short_backtrace
   9: std::rt::lang_start::{{closure}}
  10: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/ops/function.rs:259:13
      std::panicking::try::do_call
             at rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:403:40
      std::panicking::try
             at rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:367:19
      std::panic::catch_unwind
             at rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panic.rs:129:14
      std::rt::lang_start_internal::{{closure}}
             at rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/rt.rs:45:48
      std::panicking::try::do_call
             at rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:403:40
      std::panicking::try
             at rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:367:19
      std::panic::catch_unwind
             at rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panic.rs:129:14
      std::rt::lang_start_internal
             at rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/rt.rs:45:20
  11: main
  12: __libc_start_main
  13: _start

Child process terminated with status: signal: 6
>>

Empty array woking fine with Python

Python 3.7.3 (default, Jan 22 2021, 20:04:44)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.21.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import tango
In [2]: dev = tango.DeviceProxy("sys/tg_test/1")
In [3]: dev.command_inout("DevVarCharArray", [])
Out[3]: array([], dtype=uint8)
In [4]:

Figured I would raise an issue as my knowledge of C is very dangerous at best 😄