0

I'm new to GTK+ and I get a segmentation fault error when I try to compile my program. I've isolated the cause of the error down to the following lines of code.

      GtkTextBuffer *buffer; 
      char buffers[65535];
      struct ip  *ip;          
      .
      .
      .
      ip = (struct ip *)buffers;
      gtk_text_buffer_insert_at_cursor (buffer,ip->ip_protocol, -1);

(ip_protocol is a variable in the struct ip)

I'm trying to insert,at the cursor of a textview,the value of the char,"ip_protocol",situated in "buffers" using a pointer.Unfortunately I have to use a pointer in this case.Can anyone help with rectifying my code?

4

1 回答 1

1

你永远不会初始化你的buffer变量(或相关的内容buffers),所以当你传递它时它的值是未定义的 do gtk_text_buffer_insert_at_cursorGtkTextBuffer在将它传递给函数之前,您需要使其指向 a 。(根据您的评论,您在遗漏的代码部分初始化变量,因此本段不适用于您的真实代码)。

此外,您说您的ip_protocol变量是 a char,但 to 的第二个参数gtk_text_buffer_insert_at_cursor应该是一个指针。因此,这会导致分段错误也就不足为奇了。

于 2012-05-14T09:47:59.517 回答