sprintf导致总线错误(信号10) [英] sprintf leading up to bus error (signal 10)

查看:104
本文介绍了sprintf导致总线错误(信号10)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我整个上午一直在工作,终于找到了

我的总线错误(信号10)的来源。错误。来源很奇怪。错误

出现在我调用函数的任何函数中:


(void)sprintf(ptr_testing," This is my string");


这本身并不是实际错误发生的地方。在以后的任何时候发生错误

,在sprintf()调用的同一函数中生成
,其中我尝试为其中一个变量赋值

我的数据结构之一。这些行在语法上让人联想到:


((lst_vals *)userInst-> seniorData) - > lst_T_chan =(double)340.0;


其中seniorData是指向定义的lst_vals数据结构的指针

如下:


/ * seniorData的数据结构指向* /

typedef struct {

double lst_T_chan,current_T_chan,lst_t,current_t;

} lst_vals;


Any关于发生了什么的想法?它超越了我。我原本以为

这是一个简单的类型转换问题,我很确定我错了。

这是非常奇怪的,因为任何数量的命令在这两行之间将执行
行代码。上面显示的任务即时

到达程序退出时带有信号10.


提前致谢,


史蒂夫

Well I''ve been working all morning and have finally found the source of
my "bus error (signal 10)" errors. The source is odd. The error
occurs in any function where I make the function call:

(void)sprintf(ptr_testing, "This is my string");

This in itself isn''t where the actual error occurs. The error occurs
at any later point, in the same function where the sprintf() call is
made, where I try to assign a value to one of the variables in one of
my data structures. The lines are syntactically reminiscent of:

((lst_vals *)userInst->seniorData)->lst_T_chan = (double) 340.0;

Where the seniorData is a pointer to a lst_vals data structure defined
as follows:

/*data structure for seniorData to point to*/
typedef struct {
double lst_T_chan, current_T_chan, lst_t, current_t;
} lst_vals;

Any ideas on what''s going on? It''s way beyond me. I orginally thought
that it was a simple typecasting problem, I''m pretty sure I''m wrong.
It''s extremely odd because any number of commands between those two
lines of code will be executed. The instant the assignment shown above
is reached the program exits with signal 10.

Thanks in advance,

Steve

推荐答案

" steve" < SR ****** @ gmail.com>在消息中写道

news:11 ********************** @ g44g2000cwa.googlegr oups.com ...
"steve" <sr******@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
我早上一直在工作,终于找到了我的总线错误(信号10)的来源。错误。来源很奇怪。错误
发生在我调用函数的任何函数中:

(void)sprintf(ptr_testing,这是我的字符串);

这本身并不是实际错误发生的地方。错误发生在以后的任何一点,在sprintf()调用的同一函数中,我尝试为其中一个变量中的一个变量赋值
我的数据结构。这些行在语法上让人联想到:

((lst_vals *)userInst-> seniorData) - > lst_T_chan =(double)340.0;


IMO,(双)是没有必要的,因为浮点常数是双倍的

默认值。

seniorData是指向定义的lst_vals数据结构的指针,如下所示:

/ * seniorData的数据结构指向* /
typedef struct {
double lst_T_chan, current_T_chan,lst_t,current_t;
} lst_vals;

关于发生了什么的任何想法?它超越了我。我原本认为这是一个简单的类型转换问题,我很确定我错了。
这是非常奇怪的,因为这两行之间有任意数量的命令代码将被执行。到达上面显示的分配
即时,程序退出,信号为10。
Well I''ve been working all morning and have finally found the source of
my "bus error (signal 10)" errors. The source is odd. The error
occurs in any function where I make the function call:

(void)sprintf(ptr_testing, "This is my string");

This in itself isn''t where the actual error occurs. The error occurs
at any later point, in the same function where the sprintf() call is
made, where I try to assign a value to one of the variables in one of
my data structures. The lines are syntactically reminiscent of:

((lst_vals *)userInst->seniorData)->lst_T_chan = (double) 340.0;
IMO, (double) isn''t necessary as the floating point constants are double by
default.
Where the seniorData is a pointer to a lst_vals data structure defined
as follows:

/*data structure for seniorData to point to*/
typedef struct {
double lst_T_chan, current_T_chan, lst_t, current_t;
} lst_vals;

Any ideas on what''s going on? It''s way beyond me. I orginally thought
that it was a simple typecasting problem, I''m pretty sure I''m wrong.
It''s extremely odd because any number of commands between those two
lines of code will be executed. The instant the assignment shown above
is reached the program exits with signal 10.




你确定有足够的内存用于lst_vals类型的结构在哪个点是userInst-> seniorData的

地址?我不知道你正在做什么,但是这个指针演员让我怀疑是这样的。

我会期待一个分段错误然而,在这里,但你永远不知道你在写你不应该的地方打破你的b $ b $


Alex



Are you sure there''s enough memory for a structure of type lst_vals at the
address to which points userInst->seniorData? I don''t know what exactly
you''re doing but this pointer cast makes me suspect that this is the case.
I''d expect a segmentation fault here, however, but you never know what you
break by writing where you shouldn''t.

Alex


>我早上一直在工作,最后找到了
>Well I''ve been working all morning and have finally found the source of
我的总线错误(信号10)的来源。错误。来源很奇怪。错误
发生在我调用函数的任何函数中:

(void)sprintf(ptr_testing,这是我的字符串);


那么ptr_testing指向哪里?如何分配内存?

你确定有足够的内存来分配这个字符串吗?

这本身并不是实际错误发生的地方。错误发生在以后的任何一点,在sprintf()调用的同一函数中,我尝试为其中一个变量中的一个变量赋值
我的数据结构。


可能的问题:上面的sprintf()踩踏内存。

下面的行试图使用存储在重踏内存中的指针。

KABOOM !!

这些行在语法上让人联想到:

((lst_vals *)userInst-> seniorData) - > lst_T_chan =(double)340.0;

其中seniorData是指向定义的lst_vals数据结构的指针,如下所示:

/ * seniorData的数据结构指向* /
typedef struct {
double lst_T_chan,current_T_chan,lst_t,current_t;
} lst_vals;

关于发生了什么的任何想法?它超越了我。我原本以为这是一个简单的类型转换问题,我很确定我错了。
这是非常奇怪的,因为这两行代码之间的任意数量的命令都将被执行。
my "bus error (signal 10)" errors. The source is odd. The error
occurs in any function where I make the function call:

(void)sprintf(ptr_testing, "This is my string");
So where does ptr_testing point? How was that memory allocated?
Are you sure there is enough memory allocated to fit that string?
This in itself isn''t where the actual error occurs. The error occurs
at any later point, in the same function where the sprintf() call is
made, where I try to assign a value to one of the variables in one of
my data structures.
Possible problem: the sprintf() above stomps memory.
The line below tries to use a pointer stored in stomped memory.
KABOOM!!
The lines are syntactically reminiscent of:

((lst_vals *)userInst->seniorData)->lst_T_chan = (double) 340.0;

Where the seniorData is a pointer to a lst_vals data structure defined
as follows:

/*data structure for seniorData to point to*/
typedef struct {
double lst_T_chan, current_T_chan, lst_t, current_t;
} lst_vals;

Any ideas on what''s going on? It''s way beyond me. I orginally thought
that it was a simple typecasting problem, I''m pretty sure I''m wrong. It''s extremely odd because any number of commands between those two
lines of code will be executed.




这通常是一个标志缓冲区溢出问题,使用未初始化的

指针,内存踩踏等等。


Gordon L. Burditt



This is often a sign of a problem with buffer overrun, use of uninitialized
pointers, memory stomping, etc.

Gordon L. Burditt


我应该发出一个警告,我不是一个软件人,而是一个真正的电子工程师,所以这对我来说是一个未经检验的地方


ptr_testing定义为:


char * ptr_testing;


所以我没有明确分配任何内存。但是我也试过了

使用:


char ptr_testing [255];


哪个仍然可以不行。


我怀疑它与sprintf()函数有关

覆盖我需要的东西然后这个东西是

正在使用,或者在灾难性地失败之前尝试使用它。


我确定这是一个基本的东西,我在看。


再次感谢您的帮助,


Steve

I should''ve given a warning that I''m not a software guy but really an
electronics engineer so this is somewhat untested ground for me

ptr_testing is defined as:

char *ptr_testing;

So I''ve not explicitly allocated any memory. But I''ve also tried
using:

char ptr_testing[255];

Which still does not work.

I suspected it had something to do with the sprintf() function
overwritting something that I needed and then later this thing was
being used, or attempted it''s use before failing catasptrophically.

I''m sure it''s something fundamental that I''m over looking.

Again, thanks for your help,

Steve


这篇关于sprintf导致总线错误(信号10)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆