[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Possible string bug?
From: |
John W. Eaton |
Subject: |
Possible string bug? |
Date: |
Tue, 11 May 1999 15:36:30 -0500 (CDT) |
On 11-May-1999, Nick McGrogan <address@hidden> wrote:
| Being a novice Octave user I thought I should post this here in case
| I've done something really stupid, before being forward enough to
| report it as a bug...
|
| A bit weird this. The following C++ program:
|
| #include <octave/oct.h>
| #include <octave/pager.h>
|
| DEFUN_DLD (strtest, args, , "")
| {
| string invar = args(0).string_value();
|
| octave_stdout << invar << "\n";
| octave_stdout << invar.data() << "\n";
|
| return args;
| }
|
| is a simple reduction to demonstrate the problem.
|
| Given a string input this should echo it back twice to the screen,
| once as a C++ string class and then as a C-style char * string. The
| second output, however, seems to get corrupted.
|
| Typical output is:
|
| octave:1> strtest("foo")
| foo
| footrtest__Fv
| ans = foo
The problem is that string::data() doesn't return a nul-terminated
string. You need to use string::c_str() instead, or use some other
method to only print string::length() characters.
jwe