bugGNU Octave - Bugs: bug #54382, char to int conversion fails if...

 
 

bug #54382: char to int conversion fails if OCTAVE_HAVE_OVERLOAD_CHAR_INT8_TYPES is not defined

Submitter:  John W. Eaton <jwe>
Submitted:  Thu 26 Jul 2018 12:55:05 PM UTC
   
 
Category:  Libraries Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  None Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Solaris/SunOS
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 26 Jul 2018 12:55:05 PM UTC, original submission:  

The following tests failed on a Solaris build:


>>>>> processing /export/home/eaton/local/build/octave-4.4.1-rc1/liboctave/util/oct-inttypes.cc-tst
***** assert (uint8 (char (128)), uint8 (128))
!!!!! test failed
ASSERT errors for:  assert (uint8 (char (128)),uint8 (128))

  Location  |  Observed  |  Expected  |  Reason
     ()           0           128        Abs err 128 exceeds tol 0 by 1e+02
***** assert (uint8 (char (255)), uint8 (255))
!!!!! test failed
ASSERT errors for:  assert (uint8 (char (255)),uint8 (255))

  Location  |  Observed  |  Expected  |  Reason
     ()           0           255        Abs err 255 exceeds tol 0 by 3e+02
***** assert (int8 (char (128)), int8 (128))
!!!!! test failed
ASSERT errors for:  assert (int8 (char (128)),int8 (128))

  Location  |  Observed  |  Expected  |  Reason
     ()          -128         127        Abs err 255 exceeds tol 0 by 3e+02
***** assert (int8 (char (255)), int8 (255))
!!!!! test failed
ASSERT errors for:  assert (int8 (char (255)),int8 (255))

  Location  |  Observed  |  Expected  |  Reason
     ()           -1          127        Abs err 128 exceeds tol 0 by 1e+02
***** assert (uint16 (char (128)), uint16 (128))
!!!!! test failed
ASSERT errors for:  assert (uint16 (char (128)),uint16 (128))

  Location  |  Observed  |  Expected  |  Reason
     ()           0           128        Abs err 128 exceeds tol 0 by 1e+02
***** assert (uint16 (char (255)), uint16 (255))
!!!!! test failed
ASSERT errors for:  assert (uint16 (char (255)),uint16 (255))

  Location  |  Observed  |  Expected  |  Reason
     ()           0           255        Abs err 255 exceeds tol 0 by 3e+02
***** assert (int16 (char (128)), int16 (128))
!!!!! test failed
ASSERT errors for:  assert (int16 (char (128)),int16 (128))

  Location  |  Observed  |  Expected  |  Reason
     ()          -128         128        Abs err 256 exceeds tol 0 by 3e+02
***** assert (int16 (char (255)), int16 (255))
!!!!! test failed
ASSERT errors for:  assert (int16 (char (255)),int16 (255))

  Location  |  Observed  |  Expected  |  Reason
     ()           -1          255        Abs err 256 exceeds tol 0 by 3e+02
***** assert (uint32 (char (128)), uint32 (128))
!!!!! test failed
ASSERT errors for:  assert (uint32 (char (128)),uint32 (128))

  Location  |  Observed  |  Expected  |  Reason
     ()           0           128        Abs err 128 exceeds tol 0 by 1e+02
***** assert (uint32 (char (255)), uint32 (255))
!!!!! test failed
ASSERT errors for:  assert (uint32 (char (255)),uint32 (255))

  Location  |  Observed  |  Expected  |  Reason
     ()           0           255        Abs err 255 exceeds tol 0 by 3e+02
***** assert (int32 (char (128)), int32 (128))
!!!!! test failed
ASSERT errors for:  assert (int32 (char (128)),int32 (128))

  Location  |  Observed  |  Expected  |  Reason
     ()          -128         128        Abs err 256 exceeds tol 0 by 3e+02
***** assert (int32 (char (255)), int32 (255))
!!!!! test failed
ASSERT errors for:  assert (int32 (char (255)),int32 (255))

  Location  |  Observed  |  Expected  |  Reason
     ()           -1          255        Abs err 256 exceeds tol 0 by 3e+02
***** assert (uint64 (char (128)), uint64 (128))
!!!!! test failed
ASSERT errors for:  assert (uint64 (char (128)),uint64 (128))

  Location  |  Observed  |  Expected  |  Reason
     ()           0           128        Abs err 128 exceeds tol 0 by 1e+02
***** assert (uint64 (char (255)), uint64 (255))
!!!!! test failed
ASSERT errors for:  assert (uint64 (char (255)),uint64 (255))

  Location  |  Observed  |  Expected  |  Reason
     ()           0           255        Abs err 255 exceeds tol 0 by 3e+02
***** assert (int64 (char (128)), int64 (128))
!!!!! test failed
ASSERT errors for:  assert (int64 (char (128)),int64 (128))

  Location  |  Observed  |  Expected  |  Reason
     ()          -128         128        Abs err 256 exceeds tol 0 by 3e+02
***** assert (int64 (char (255)), int64 (255))
!!!!! test failed
ASSERT errors for:  assert (int64 (char (255)),int64 (255))

  Location  |  Observed  |  Expected  |  Reason
     ()           -1          255        Abs err 256 exceeds tol 0 by 3e+02


This is happening because the overload for constructing intNDArray<T> objects from char is not defined because OCTAVE_HAVE_OVERLOAD_CHAR_INT8_TYPES is not defined.  This configuration variable is set correctly, as these overloads are not possible on this system.  So we need another solution for storing or converting character types.

The constructor is in oct-inttypes.h:


#if defined (OCTAVE_HAVE_OVERLOAD_CHAR_INT8_TYPES)
  // Always treat characters as unsigned.
  octave_int (char c)
    : ival (octave_int_base<T>::truncate_int (static_cast<unsigned char> (c)))
  { }
#endif


It would be good if we could do this at the level of intNDArray<T>, but if not, we will have to do it by overloading the as_{u,}int{8,16,32,64} functions in octave_value and fixing any other locations where this constructor is called individually.

I set the OS field to Solaris/SunOS because that's where the bug was discovered, but this probably applies to any system where OCTAVE_HAVE_OVERLOAD_CHAR_INT8_TYPES is not defined.  If you force that value on another system, you should see the same problem.

There is also one more place in oct-stream.cc where this configuration variable is used, but in that case, it should not change behavior.

John W. Eaton <jwe>
Group administrator

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Submitted the item)
  •  

    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.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.13-a854.
    Corresponding source code