bugGNU Octave - Bugs: bug #64051, ...

 
 

bug #64051: undo_string_escapes("\0") returns an empty string

Submitter:  Wanghao Xu <newcomer00>
Submitted:  Sat 15 Apr 2023 03:10:11 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 8.1.0 Operating System:  * Any
Fixed Release:  8.3.0 Planned Release:  8.3.0
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 16 Apr 2023 04:14:53 PM UTC, comment #3: 

I fixed this on the stable branch in this changeset: http://hg.savannah.gnu.org/hgweb/octave/rev/783b69da1b45.  This will be a part of the 8.3 bug fix release, although 8.2 was just released so I do not have an idea of when this code will be readily available.  If you need it immediately you can always get the source code from the Mercurial repository and build Octave yourself.

Marking bug as Fixed and closing report.

Rik <rik5>
Group administrator
Sun 16 Apr 2023 10:23:04 AM UTC, comment #2: 

Thank you for the quick response! I also think the correct result is '\0' with the size of 1x2.

Wanghao Xu <newcomer00>
Sun 16 Apr 2023 02:32:51 AM UTC, comment #1: 

Yes, I think you are correct that the string "\0" should be generated for the null byte.  The code is in libinterp/corefcn/utils.cc:undo_string_escape.  It is quoted below


const char * undo_string_escape (char c)
{
  if (! c)
    return "";

  switch (c)
    {
    case '\0':
      return R"(\0)";

    case '\a':
      return R"(\a)";


As you can see, it looks like it is supposed to generate "\0".

Marking as confirmed.

Rik <rik5>
Group administrator
Sat 15 Apr 2023 03:10:11 PM UTC, original submission:  

Related Docs

https://docs.octave.org/v8.1.0/Common-String-Operations.html#index-undo_005fstring_005fescapes

: newstr = undo_string_escapes (string)
Convert special characters in strings back to their escaped forms.

Steps to Reproduce

Commands:

result = undo_string_escapes("\0")
whos result


The actual outputs:

result =
Variables visible from the current scope:

variables in scope: top scope

  Attr   Name        Size                     Bytes  Class
  ====   ====        ====                     =====  =====
         result      0x0                          0  char

Total is 0 elements using 0 bytes


My expected outputs:

result = \0
Variables visible from the current scope:

variables in scope: top scope

  Attr   Name        Size                     Bytes  Class
  ====   ====        ====                     =====  =====
         result      1x2                          2  char

Total is 2 elements using 2 bytes


Related Srcs

https://docs.octave.org/doxygen/dev/d7/da9/utils_8cc_source.html#l00986

 const char * undo_string_escape (char c)
 {
   if (! c)
     return "";

   switch (c)
     {
     case '\0':
       return R"(\0)";

     case '\a':
       return R"(\a)";

     case '\b': // backspace
       return R"(\b)";
   ...


I noticed that if c == '\0', the function will directly return "" instead of entering the first case of the switch block, thus undo_string_escapes("\0") will return an empty string.
I am wondering if this is a bug or an expected behavior? Thanks in advance for any responses!

Wanghao Xu <newcomer00>

 

(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 rik5 (Posted a comment)
  • -email is unavailable- added by newcomer00 (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.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-04-16 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
        Fixed ReleaseNone 8.3.0
        Planned ReleaseNone 8.3.0
    2023-04-16 rik5 StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-aa77.
    Corresponding source code