segmentation-fault

Why do I get a segmentation fault in my GTK+ signal callback?

醉酒当歌 提交于 2020-01-09 11:27:07
问题 I am trying to measure the size of a GTK label: #include <gtk/gtk.h> static void map_event(GtkWidget *window, gpointer lab) { g_print( "In the callback..\n" ); GtkWidget *label = GTK_WIDGET(lab); g_print( "Everything is ok..\n" ); } static void activate (GtkApplication* app, gpointer user_data) { GtkWidget *window = gtk_application_window_new (app); gtk_window_set_title (GTK_WINDOW (window), "Window1"); gtk_window_set_default_size (GTK_WINDOW (window), 200, 280); GtkWidget *grid = gtk_grid

Segmentation fault using strcat

我与影子孤独终老i 提交于 2020-01-09 05:43:04
问题 Here is my code : char *name, name_log="log-"; ------getting 'name' from user----- strcat(name_log, name); char ext[] = ".log"; strcat(name_log, ext); What i need to end up with is name_log = "log-'name'.log" but Im getting a segmentation fault error :((. What am I doing wrong and how can I fix it ? Thx 回答1: For a start, if this is your code: char *name, name_log="log-"; then name_log is a char, not a char pointer. Assuming that's a typo, you cannot append to string literals like that.

strtok segmentation fault

大憨熊 提交于 2020-01-08 14:26:41
问题 I am trying to understand why the following snippet of code is giving a segmentation fault: void tokenize(char* line) { char* cmd = strtok(line," "); while (cmd != NULL) { printf ("%s\n",cmd); cmd = strtok(NULL, " "); } } int main(void) { tokenize("this is a test"); } I know that strtok() does not actually tokenize on string literals, but in this case, line points directly to the string "this is a test" which is internally an array of char . Is there any of tokenizing line without copying it

Segfault doesn't happen [duplicate]

别来无恙 提交于 2020-01-07 09:01:25
问题 This question already has answers here : Undefined, unspecified and implementation-defined behavior (8 answers) Closed 3 years ago . I have the following c code: #include <stdint.h> #include <stdio.h> int main (){ uint8_t *array; int i=0; for(;i<32120;i++) printf("Array[%d] = %d \n",i,*(array+i)); } As I don't declare the memory for array, I would expect this code to segfault on the second iteration, but it's not the case (it happens at i==3295 on my raspberry, and larger random i value on my

Circular Doubly Linked List - Segmentation fault: 11 [closed]

[亡魂溺海] 提交于 2020-01-07 03:57:14
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I'm trying to implement a circular doubly linked list but I keep getting a segmentation fault: 11 error (I believe it's because of the add and delete functions). I have no idea whether my code is even close, but I can't get past this error to test it properly. This is the code I have that I believe is involved:

I've got a segmentation fault but I dont find oO?

妖精的绣舞 提交于 2020-01-06 18:08:24
问题 It should sort with merge. There are two functions the merge and the sort merge. Some not known functions (read array from file and print array) are totally functional in an input file. Valgrind show me that the failure is at the allocation from array2 and when it read and write at the 3rd while-loop in void merge. void merge(int* array, int start, int middle, int end) { int size = end - start + 1; int *array2 = malloc(size*sizeof(array2)); int k = start; int m = middle + 1; int i = 0; int j

'C' Segmentation fault with 2d array

落花浮王杯 提交于 2020-01-06 18:05:16
问题 Can anybody explain me why this code doesn't work? #include <stdio.h> #include <stdlib.h> void findAndPrint(char *arr[], int year, int month, int day); int main() { char *dayTab[] = { {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} }; findAndPrint(dayTab, 3, 3, 3); getchar(); return 0; } void findAndPrint(char *arr[], int year, int month, int day ){ int d = 0; if(month > 12 || month < 1 || day > 31 || day<1) return; int leap = ((year%4==0 &&

Eigen segfault no optimizations Solaris

≡放荡痞女 提交于 2020-01-06 14:12:56
问题 I have the following code: #include <Eigen/Dense> struct States { // Eigen::VectorXd v; Eigen::VectorXd v{Eigen::VectorXd::Ones(2)}; States() { // v.resize(2); // v << 1, 1; } }; States st; int main() {} Whenever I build the project under Solaris 11 (with g++4.9), with no optimizations, I get a segfault (core dumped) when running. After some digging and step-by-step debugging I think the faulty line is in DenseCoeffBase.h , inside function copyPacket , namely the line 537 derived().template

segmentation fault due to initialize() function when changing the size of the huge page allocation

a 夏天 提交于 2020-01-06 12:44:23
问题 I encounter segmentation fault in my program when I play with the size of the memory that I want to allocate with huge page, i.e., when I define LENGTH = 4*1024, there is seg fault. When I define 4*1024*1024, there is no seg fault. What is the root cause of this? Code below: #define _POSIX_C_SOURCE 199309 #define _GNU_SOURCE #include <sched.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/mman.h> #include <fcntl.h> #include <time.h> #include <string.h> #include

SegFault with Producer/Consumer File Copy

不羁岁月 提交于 2020-01-06 12:37:07
问题 back with another segfault. Not sure why, as this readdir line is the same one i've been using in other file copy assignments. Below is the code I crafted in lieu of the assignment shared here. I have commented where the segfault occurs in hopes of aiding better minds find my flaw! This is copyDirs.cpp //cmd: ./a.out [#ofConsumerThreads] [src directory] [dest directory] #include "copyDirs.h" int main(int ac,char* av[]) { pthread_mutex_init(&buflock,NULL); pthread_t prodT; if(ac == 4) { int