c_str()执行SEGSEGV [英] c_str() does a SEGSEGV
问题描述
嗨
我有一个程序,其中我有以下声明。
sprintf(somevar,"%s /% s。%s",PREFIX.c_str(),MIDDLE.c_str(
),SUFFIX.c_str());
这里是PREFIX,MIDDLE和SUFFIX都是常量字符串。
这个工作正常,但最近在接近1000次成功运行后,我的
程序被SIGSEGV抛弃了。
我在gdb提示符下对核心文件做了一个bt,发现问题是
c_str()
我正在使用gcc 3.2.3
libstdc ++。so.5
RH linux AS 3上的
是spriontf语句是的,还是有更好的方法。
谢谢
Shyam
Hi
I have a program within which i have the following statement.
sprintf(somevar,"%s/%s.%s",PREFIX.c_str( ),MIDDLE.c_str(
),SUFFIX.c_str( ) );
Here PREFIX, MIDDLE and SUFFIX are all const strings.
This works fine but recently after close to 1000 successful runs my
program dumped with SIGSEGV.
I did a bt on the core file at gdb prompt and found that the problem is
with c_str( )
I am using gcc 3.2.3
libstdc++.so.5
on RH linux AS 3.
Is the spriontf statement correct , or is there any better way.
thanks
Shyam
推荐答案
Dnia 27 Sep 2006 02:47:52 -0700,shyam napisa3(a):
Dnia 27 Sep 2006 02:47:52 -0700, shyam napisa3(a):
sprintf(somevar,"%s /% s。%s",PREFIX.c_str(),MIDDLE.c_str(
),SUFFIX.c_str() );
sprintf(somevar,"%s/%s.%s",PREFIX.c_str( ),MIDDLE.c_str(
),SUFFIX.c_str( ) );
什么是somevar ?
What is "somevar" ?
spriontf语句是否正确,或者有更好的方法。
Is the spriontf statement correct , or is there any better way.
您是否尝试使用stringstream或正常字符串连接?
-
SirMike - http://www.sirmike.org
C让你轻松拍摄自己的脚; C ++让它变得更难,但是当你这样做时,它会让你的整条腿感到震惊。 - Bjarne Stroustrup
Did you try to use stringstream or normal string concatenation?
--
SirMike - http://www.sirmike.org
C makes it easy to shoot yourself in the foot; C++ makes it harder, but
when you do, it blows away your whole leg. - Bjarne Stroustrup
shyam写道:
shyam wrote:
嗨
我有一个程序,其中我有以下声明。
sprintf(somevar,"%s /%s。%s",PREFIX.c_str(),MIDDLE.c_str(
),SUFFIX.c_str());
这里的PREFIX,MIDDLE和SUFFIX都是const字符串。
这个工作正常但最近在接近1000次成功运行之后我用
程序转储了SIGSEGV。
我在gdb提示符下对核心文件做了一个bt并发现问题是
with c_str()
我正在使用gcc 3.2.3
libstdc ++。so.5
RH linux AS 3上的
spriontf语句是否正确,或者有更好的方法。
Hi
I have a program within which i have the following statement.
sprintf(somevar,"%s/%s.%s",PREFIX.c_str( ),MIDDLE.c_str(
),SUFFIX.c_str( ) );
Here PREFIX, MIDDLE and SUFFIX are all const strings.
This works fine but recently after close to 1000 successful runs my
program dumped with SIGSEGV.
I did a bt on the core file at gdb prompt and found that the problem is
with c_str( )
I am using gcc 3.2.3
libstdc++.so.5
on RH linux AS 3.
Is the spriontf statement correct , or is there any better way.
我会责怪你的一些(未显示)代码,可能
会覆盖字符串的一些内部存储器,因此
c_str()段错误。
< OT>
如果您使用的是32位平台,请尝试valgrind精确定位
错误。
< / OT>
HTH,
- J. br />
I''d blame some of your (not shown) code that probably
overwrites some internal memory of the strings, hence
the c_str() segfault.
<OT>
If you are on a 32-bit platform, try valgrind to pinpoint
the error.
</OT>
HTH,
- J.
我没有使用字符串或字符串流连接。
而且我没有以任何其他方式使用这些const字符串。
>
我觉得最好将这三个字符串连接成一个字符串
对象,然后再将c_str()连接到该对象上。
Jacek Dziedzic写道:
I havent used string or stringstream concatenation.
And i am not using these const strings in any other way.
I feel it is better to concatenate these three strings into one string
object and then so a c_str( ) on that object.
Jacek Dziedzic wrote:
shyam写道:
shyam wrote:
嗨
我有一个程序,其中我有以下声明。
sprintf(somevar,"%s /%s。%s",PREFIX.c_str(),MIDDLE。 c_str(
),SUFFIX.c_str());
这里的PREFIX,MIDDLE和SUFFIX都是常量字符串。
这样工作正常但是最近在接近1000次成功运行之后,我用
程序转储了SIGSEGV。
我在gdb提示符下对核心文件做了一个bt,发现问题是
with c_str()
我正在使用gcc 3.2.3
libstdc ++。so.5
spriontf语句是否正确,或者有更好的方法。
Hi
I have a program within which i have the following statement.
sprintf(somevar,"%s/%s.%s",PREFIX.c_str( ),MIDDLE.c_str(
),SUFFIX.c_str( ) );
Here PREFIX, MIDDLE and SUFFIX are all const strings.
This works fine but recently after close to 1000 successful runs my
program dumped with SIGSEGV.
I did a bt on the core file at gdb prompt and found that the problem is
with c_str( )
I am using gcc 3.2.3
libstdc++.so.5
on RH linux AS 3.
Is the spriontf statement correct , or is there any better way.
我会责怪你的一些(未显示)代码可能
覆盖字符串的一些内部存储器,因此
c_str()段错误。
< OT>
如果您使用的是32位平台,请尝试valgrind精确定位
错误。
< / OT>
HTH,
- J.
I''d blame some of your (not shown) code that probably
overwrites some internal memory of the strings, hence
the c_str() segfault.
<OT>
If you are on a 32-bit platform, try valgrind to pinpoint
the error.
</OT>
HTH,
- J.
这篇关于c_str()执行SEGSEGV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!