segmentation-fault

Why does this code to modify a string not work?

試著忘記壹切 提交于 2020-01-28 04:38:12
问题 With c-style strings, how do you assign a char to a memory address that a character pointer points to? For example, in the example below, I want to change num to "123456", so I tried to set p to the digit where '0' is located and I try to overwrite it with '4'. Thanks. #include <stdio.h> #include <stdlib.h> int main() { char* num = (char*)malloc(100); char* p = num; num = "123056"; p = p+3; //set pointer to where '4' should be p = '4'; printf("%s\n", num ); return 0; } 回答1: That code won't

Segmentation Error in C program When Run

≯℡__Kan透↙ 提交于 2020-01-25 21:01:09
问题 I've tried malloc , and no malloc and it will build but not run or compile. When I run the code on codepad.org it gives me a segmentation error. I have an array of structures I'm inputting and I'm searching through them for a specific item. That's as far as I got and no compile. The code is as follows (I used netbeans, codeblocks, and visual basic 2012 programs): #include <stdio.h> #include <stdlib.h> #include <string.h> #define SIZE 20 #define BLOODTYPESIZE 4 #define MAX 120000 typedef

Segmentation fault when using qsort and printf

偶尔善良 提交于 2020-01-25 20:58:06
问题 I'm trying to make a program to crack passwords by searching through a file of md5 hashes and using bsearch to find them in a rockyou database. My problem is that I'm running into a segmentation fault that is either caused by my qsort or my printf (I've run Valgrind and it says printf, but manipulating qsort changes the error output). I can't seem to find the solution online, though I've tried flushing stdout and different ways to size the array in the qsort function. char **dict = read_dict(

memory efficient Python (pandas) aggregates of categories from one csv file per period

ぐ巨炮叔叔 提交于 2020-01-25 18:31:00
问题 I am trying to avoid a segmentation fault with either pandas or IOPro (still investigating), so I am looking for alternative solutions, esp. more efficient ones. The code below runs fine with small data but crashed reading in 90 monthly panels of a few GBs on a Linux server with 256 GB RAM, versions pandas 0.16.2 np19py26_0, iopro 1.7.1 np19py27_p0, and python 2.7.10 0. What I do here is that I aggregate accounts of drug purchase records (cost in TKOST) for each person (LopNr) and month,

segmentation fault in findcontours opencv

瘦欲@ 提交于 2020-01-25 13:29:29
问题 I am trying to detect a ball and draw boundaries to it. It shows the error segmentation fault (core dumped) The mistake is somewhere here, vector<vector<Point> > contours; vector<Vec4i> hierarchy; Mat itt = Mat::zeros( imgThresholded.size(), CV_8UC1 ); itt = imgThresholded*255; Canny( itt ,itt, 10, 30, 3 ); vector<vector<Point> > contours_poly( contours.size() ); vector<Point2f>center( contours.size() ); vector<float>radius( contours.size() ); vector<Rect> boundRect( contours.size() ); imshow

Mysql_num_rows() Segfaults

孤者浪人 提交于 2020-01-25 13:05:08
问题 I'm writing a program using C++ and the MySQL C API (version 5.1.31 ubuntu2). However, if the query is UPDATE then I get a Segmentation Fault error when executing the line "RowsReturned = mysql_num_rows( Result );". //this code snippet contains only the relevant code MYSQL_RES *Result; long RowsReturned; MYSQL_RES *MYSQLDB::RunQuery( const char* Query ) { if( mysql_query( Connection, Query) ) { std::cout << "Error: " << mysql_error( Connection ); exit(1); } Result = mysql_store_result(

Mysql_num_rows() Segfaults

倖福魔咒の 提交于 2020-01-25 13:04:16
问题 I'm writing a program using C++ and the MySQL C API (version 5.1.31 ubuntu2). However, if the query is UPDATE then I get a Segmentation Fault error when executing the line "RowsReturned = mysql_num_rows( Result );". //this code snippet contains only the relevant code MYSQL_RES *Result; long RowsReturned; MYSQL_RES *MYSQLDB::RunQuery( const char* Query ) { if( mysql_query( Connection, Query) ) { std::cout << "Error: " << mysql_error( Connection ); exit(1); } Result = mysql_store_result(

Store data from binary file into dynamic array of strings

随声附和 提交于 2020-01-25 03:10:33
问题 I have a binary file where I store numbers as strings in this fashion: 11 43 89 101 etc I want, by using only system commands, to read the numbers stored and store them in a string dynamic array, because i don't know how long the strings will end up being or how many. Here is the relevant code: char **positions; int all_names=0,i,j; fd=open(argv[2],O_RDWR|O_CREAT,S_IRWXU); i=0; j=0; do{ positions=(char**)malloc(sizeof(char*)); (*positions)[i]=(char*)malloc((MAX_SIZE+1)*sizeof(char)); do{ read

Mod_wsgi worker processes segmentation fault (11)

一个人想着一个人 提交于 2020-01-24 16:06:16
问题 I am having a problem with my django application, which is hosted with apache/mod_wsgi. I added some matplotlib code into the application, and apache worker processes now crashing. I reduced this problem to the following: Without any matplotlib imports application works ok when "import matplotlib" is added anywhere in the application, worker processes die with segfault and users see no reply from server "import matplotlib" works just fine in commandline python interpreter - segfault happens

Mod_wsgi worker processes segmentation fault (11)

允我心安 提交于 2020-01-24 16:04:48
问题 I am having a problem with my django application, which is hosted with apache/mod_wsgi. I added some matplotlib code into the application, and apache worker processes now crashing. I reduced this problem to the following: Without any matplotlib imports application works ok when "import matplotlib" is added anywhere in the application, worker processes die with segfault and users see no reply from server "import matplotlib" works just fine in commandline python interpreter - segfault happens