octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[50 character or so descriptive subject here (for reference)]


From: Douglas Eck
Subject: [50 character or so descriptive subject here (for reference)]
Date: Thu, 18 Oct 2001 11:51:24 +0200

To: address@hidden
Cc: doug
Subject: [50 character or so descriptive subject here (for reference)]

Bug report for Octave 2.0.16.92 configured for i386-pc-linux-gnu

Description:
-----------

Using const char * c = args(0).string_value().c_str();
to get a string from the argument vector sometimes results
in unpredictable results.

Repeat-By:
---------

/*
This code snippet shows that using c_str() has
unpredictable results when parsing args in an .oct file.

This might not be an octave bug (in fact, it probably isn't)
but it took me a while to find so I wanted to submit it. 

I am running the latest debian unstable.

Here is a test run of this code on my system:

432 ruchetta ~/beat/dynamic>mkoctfile -v bad_cstr.cc
c++ -c -fPIC -I/usr/include/octave-2.1.34 -I/usr/include/octave-2.1.34/octave 
-I/usr/include -mieee-fp -fno-implicit-templates -O2 bad_cstr.cc -o bad_cstr.o
c++ -shared -o bad_cstr.oct bad_cstr.o
433 ruchetta ~/beat/dynamic>octave
GNU Octave, version 2.1.34 (i386-pc-linux-gnu).
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 John W. Eaton.
This is free software with ABSOLUTELY NO WARRANTY.
For details, type `warranty'.

*** This is a development version of Octave.  Development releases
*** are provided for people who want to help test, debug, and improve
*** Octave.
***
*** If you want a stable, well-tested version of Octave, you should be
*** using one of the stable releases (when this development release
*** was made, the latest stable version was 2.0.16).

PS1 = Octave >>
PS2 =
beep_on_error = 0
default_save_format = mat-binary
define_all_return_values = 0
do_fortran_indexing = 0
empty_list_elements_ok = 1
fixed_point_format = 1
implicit_num_to_str_ok = 1
implicit_str_to_num_ok = 1
ok_to_lose_imaginary_part = 1
page_screen_output = 0
prefer_column_vectors = 0
prefer_zero_one_indexing = 1
print_empty_dimensions = 0
treat_neg_dim_as_zero = 1
warn_function_name_clash = 0
whitespace_in_literal_matrix = traditional
Octave >> 
bad_cstr("12345678901234567890123456789012345678901234567890123456789012345678901234567890")
Test 1 with broken c_str()
Incoming char * c is 7890123456789012345678901234567890123456789012345678
     New char * n1 is 
12345678901234567890123456789012345678901234567890123456789012345678

Test 2 with explicit copy from the string
 Old string s is 
12345678901234567890123456789012345678901234567890123456789012345678901234567890
New char * n2 is 
12345678901234567890123456789012345678901234567890123456789012345678901234567890
Octave >>
*/

#include <octave/oct.h>


DEFUN_DLD (bad_cstr, args, ,
           "call like this: cpystr(string x) where x is a long string as in 
this example: 
            
bad_cstr(\"12345678901234567890123456789012345678901234567890123456789012345678901234567890\")
            ") 
{
  octave_value_list retval;
  const char * c = args(0).string_value().c_str();
  int sz=strlen(c);
  char * n1 = new char[sz];
  strcpy(n1,c);
  cout << "Test 1 with broken c_str() " << endl;
  cout << "Incoming char * c is " << c << endl;
  cout << "     New char * n1 is "  << n1 << endl;

  cout << endl << "Test 2 with explicit copy from the string " << endl;
  string s = args(0).string_value();
  char * n2 = new char[sz];
  for (int i=0;i<sz;i++) 
    n2[i]=s[i];
  cout << " Old string s is " << s << endl;
  cout << "New char * n2 is " << n2 << endl;

  return retval;
}


Fix:
---

 I worked around it by doing explicit copies from the
 std::string rather than the char * from c_str(). 
 Perhaps (probably?) this is a bug in my debian distro,
 not in octave.



Configuration (please do not edit this section):
-----------------------------------------------

uname output:     Linux ruchetta 2.4.7 #1 Thu Sep 27 14:36:30 CEST 2001 i686 
unknown
configure opts:   --prefix=/usr --datadir=/usr/share --libdir=/usr/lib 
--libexecdir=/usr/lib --infodir=/usr/share/info --mandir=/usr/share/man 
--with-g77 --enable-dl --enable-shared --enable-lite-kernel --host i386-linux
Fortran compiler: g77
FFLAGS:           -O2
F2C:              
F2CFLAGS:         
FLIBS:            -lg2c -lm -L/usr/lib/gcc-lib/i386-linux/2.95.4 -lm
CPPFLAGS:         
INCFLAGS:         -I/usr/include/octave-2.0.16.92 
-I/usr/include/octave-2.0.16.92/octave -I/usr/include
C compiler:       gcc, version 2.95.4 20010319 (Debian prerelease)
CFLAGS:           -DHAVE_CONFIG_H -mieee-fp -O2
CPICFLAG:         -fPIC
C++ compiler:     c++, version 2.95.4 20010319 (Debian prerelease)
CXXFLAGS:         -DHAVE_CONFIG_H -mieee-fp -fno-rtti -fno-exceptions 
-fno-implicit-templates -O2
CXXPICFLAG:       -fPIC
LDFLAGS:          -s
LIBFLAGS:         -L/usr/lib/octave-2.0.16.92
RLD_FLAG:         -Xlinker -rpath -Xlinker /usr/lib/octave-2.0.16.92
TERMLIBS:         -lncurses
LIBS:             
LEXLIB:           
LIBPLPLOT:        
LIBDLFCN:         
DEFS:

  -DOCTAVE_SOURCE=1 -DSEPCHAR=':' -DSEPCHAR_STR=":" -DUSE_READLINE=1
  -D__NO_MATH_INLINES=1 -DCXX_NEW_FRIEND_TEMPLATE_DECL=1 -DHAVE_LIBM=1
  -DF77_APPEND_UNDERSCORE=1 -DOCTAVE_LITE=1 -DSIZEOF_SHORT=2
  -DSIZEOF_INT=4 -DSIZEOF_LONG=4 -DHAVE_ALLOCA_H=1 -DHAVE_ALLOCA=1
  -DNPOS=string::npos -DSTDC_HEADERS=1 -DHAVE_DIRENT_H=1
  -DTIME_WITH_SYS_TIME=1 -DHAVE_SYS_WAIT_H=1 -DHAVE_ASSERT_H=1
  -DHAVE_CURSES_H=1 -DHAVE_DLFCN_H=1 -DHAVE_FCNTL_H=1 -DHAVE_FLOAT_H=1
  -DHAVE_FNMATCH_H=1 -DHAVE_GLOB_H=1 -DHAVE_GRP_H=1 -DHAVE_LIMITS_H=1
  -DHAVE_MEMORY_H=1 -DHAVE_NCURSES_H=1 -DHAVE_POLL_H=1 -DHAVE_PWD_H=1
  -DHAVE_SGTTY_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_SYS_IOCTL_H=1
  -DHAVE_SYS_PARAM_H=1 -DHAVE_SYS_POLL_H=1 -DHAVE_SYS_RESOURCE_H=1
  -DHAVE_SYS_SELECT_H=1 -DHAVE_SYS_STAT_H=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VFPRINTF=1
  -DHAVE_VSPRINTF=1 -DHAVE_WAITPID=1 -DHAVE_PROGRAM_INVOCATION_NAME=1
  -DHAVE_LIBDL=1 -DHAVE_DLOPEN=1 -DHAVE_DLSYM=1 -DHAVE_DLERROR=1
  -DHAVE_DLCLOSE=1 -DWITH_DL=1 -DWITH_DYNAMIC_LINKING=1 -DHAVE_FINITE=1
  -DHAVE_ISNAN=1 -DHAVE_ISINF=1 -DHAVE_ACOSH=1 -DHAVE_ASINH=1
  -DHAVE_ATANH=1 -DHAVE_ERF=1 -DHAVE_ERFC=1 -DHAVE_ST_BLKSIZE=1
  -DHAVE_ST_BLOCKS=1 -DHAVE_ST_RDEV=1 -DHAVE_TM_ZONE=1 -DHAVE_GR_PASSWD=1
  -DEXCEPTION_IN_MATH=1 -DRETSIGTYPE=void -DSYS_SIGLIST_DECLARED=1
  -DHAVE_SYS_SIGLIST=1 -DHAVE_POSIX_SIGNALS=1 -DHAVE_GETRUSAGE=1
  -DHAVE_TIMES=1 -DGNUPLOT_HAS_MULTIPLOT=1 -DGNUPLOT_HAS_FRAMES=1



reply via email to

[Prev in Thread] Current Thread [Next in Thread]