gpt4 book ai didi

c - 地址越界

转载 作者:太空宇宙 更新时间:2023-11-04 04:43:20 24 4
gpt4 key购买 nike

crash --- cir_debug_log
cir_debug_log = $7 = {
buffer = 0xac3d83097f040056 <Address 0xac3d83097f040056 out of bounds>,

crash --- print *cir_debug_log->buffer
Cannot access memory at address 0xac3d83097f040056
gdb: gdb request failed: print *cir_debug_log->buffer
crash ---

这里定义了一个全局结构

typedef struct circular_buffer 

char *buffer;
unsigned capacity;
unsigned head_offset;
unsigned tail_offset;
volspin_t vxl_lock;

extern struct circular_buffer cir_debug_log;

我正在初始化它的驱动程序加载时间,并在整个过程中跟踪它的地址,这不会改变。

cb->buffer : mzalloc_sleep(25000* sizeof(char));

但不知何故,我无法通过 CRASH 打印 cir_debug_log->buffer 中存在的字符串。它正确地复制了我检查过的这个缓冲区中的字符串。cb->buffer 的地址没有改变,但在崩溃时它显示不同的地址。


cb_push_data: end trying to print messgae with cb->buffer contains buffer_content=
"Purging msg accumulated during reonline operation "

这是我的字符串,它也应该通过崩溃打印。


这是我的问题::

  1. 我永远不会改变这个缓冲区的地址。出于存储目的,我正在使用尾部偏移量(像这样 *(cb->buffer + cb->tail_offset) = ch; 并像这样增加 tail_offset cb->tail_offset = (++cb->tail_offset)%cb->能力;

  2. 我很好奇capacity,head_offset和tail_offset的内容。请查看崩溃 o/p。

崩溃——cir_debug_logcir_debug_log:$7:缓冲区——0xac3d83097f040056,容量——67131560,head_offset——2303465086,tail_offset——1156221409,vxl_lock -- 000

最佳答案

I see you have this code displayed, which is missing most of the initialization 
and what is displayed contains some syntax errors

typedef struct circular_buffer
{ // this line is missing
char *buffer;
unsigned capacity;
unsigned head_offset;
unsigned tail_offset;
volspin_t vxl_lock;
} // this line is missing

extern struct circular_buffer cir_debug_log;


// where is this declaration of 'cb'?
struct circular_buffer *cb = cir_debug_log;

// where is the initialization of the other fields?
cb->capacity = 25000 * sizeof(char);
cb->head_offset = 0;
cd->tail_offset = 0;

// this has a syntax error: ':' should be '='
cb->buffer : mzalloc_sleep(25000* sizeof(char));


BTW:
it is normal to write to the *head* and read from the *tail*.

关于c - 地址越界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23725472/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com