segmentation-fault

Multidimensional array on the heap - C

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 00:26:32
I am learning C and trying to make a function that would create an array of arrays of strings. #include <stdio.h> #include <stdlib.h> #include <string.h> void parse(char ***aoa) { char *string = calloc(9, sizeof(char)); //create a string of size 8+1 strcpy(string, "hi world"); // put text in that array char **array = calloc(10, sizeof(char *)); //create an array of strings aoa = calloc(10, sizeof(char *)); //create and array of arrays aoa[0] = array; //assign string array to the 0th elements of new array array[0] = string; //assign our string to 0th element of string carry printf("%s\n", aoa[0

Segmentation fault in std function std::_Rb_tree_rebalance_for_erase ()

不打扰是莪最后的温柔 提交于 2019-12-06 20:17:29
(Note to any future readers: The error, unsurprisingly, is in my code and not std::_Rb_tree_rebalance_for_erase () ) I'm somewhat new to programming and am unsure how to deal with a segmentation fault that appears to be coming from a std function. I hope I'm doing something stupid (i.e., misusing a container), because I have no idea how to fix it. The precise error is Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: 0x000000000000000c 0x00007fff8062b144 in std::_Rb_tree_rebalance_for_erase () (gdb) backtrace #0 0x00007fff8062b144 in std:

Meaning of Exit Code 11 in C?

狂风中的少年 提交于 2019-12-06 18:27:44
问题 What's the general meaning of an exit code 11 in C? I've looked around and can not find a definitive answer so I thought I would ask here. It comes when i try to add an element to a vector. 回答1: You didn't find a definitive answer because there isn't one. It's up to the author of the program to decide what exit codes they wish to use. Standard C only says that exit(0) or exit(EXIT_SUCCESS) indicate that the program is successful, and that exit(EXIT_FAILURE) indicates an error of some kind.

Mex dynamic memory management issue with std::vector in linked external DLL; Segmentation error

∥☆過路亽.° 提交于 2019-12-06 18:16:25
I am trying to create a mex file that interfaces MATLAB with an external C++ library that communicates with some hardware. An imported library and precompiled DLL (.lib and .dll) are provided by the hardware vendor for my version of VC++ and I was able to implement them in C++ without any issue. However, I ran into segmentation error at run time when the code is written as a mex(compiled with the same version of VC++). After some investigation with the VC++ debugger, the likely culprit seems to be the fact that one of the external dll functions returns the data type std::vector, and probably

segfault using SWIG converted code for tcl

旧城冷巷雨未停 提交于 2019-12-06 17:01:30
I'm having a segmentation fault with my program. In fact I write a library in C++ and convert it for tcl using SWIG. The segfault occurs here: return Tcl_NewIntObj(static_cast< int >(value)); where value=0 the gdb back trace shows: (gdb) bt #0 0x000054b6 in ?? () #1 0xb6650d5d in SWIG_From_long (value=0) at mntdisplay_wrap.cc:1712 #2 SWIG_From_int (value=0) at mntdisplay_wrap.cc:1722 #3 Testguimnt_Init (interp=0x9714e28) at mntdisplay_wrap.cc:3774 #4 0xb76748fe in Tcl_LoadObjCmd () from /opt/ActiveTcl-8.6/lib/libtcl8.6.so #5 0xb75d02af in TclNREvalObjv () from /opt/ActiveTcl-8.6/lib/libtcl8.6

Minimal C/C++ program that segfaults? [duplicate]

拥有回忆 提交于 2019-12-06 16:26:15
This question already has answers here : What is the easiest way to make a C++ program crash? (29 answers) Closed 5 years ago . I'm trying to set up the way my server handles core dumps. In order to test it, I'd need a program that always segfaults. Is there a simple example program that always segfaults? main; is portable, and segfault in 5chars. main() { *(int *)0xdeadbeef = 37; } should do it. try this: long* ptr = 0x0; //-- you can also use other random values and likely you will segfault printf("%f", *ptr); You can try: main() { char *p = NULL; char c = *p; } this should die: int main() {

pthread_create causing segmentation fault

十年热恋 提交于 2019-12-06 16:05:36
My program contains the following code. pthread_t PThreadTable[32]; for (i=1; i<P; i++) // Checked with P = 4 { long i, Error; printf( "pthread_create %d!\n", i ); Error = pthread_create(&PThreadTable[i], NULL, (void * (*)(void *))(SlaveStart), NULL); if (Error != 0) { printf("Error in pthread_create().\n"); exit(-1); } } SlaveStart(); The code gives segmentation fault on calling pthread_create (checked through gdb and valgrind ). Why so? Its because you redeclare variable i inside the loop. The variable inside the loop is being used and it contains garbage value. That is why, the expression

need explanation on why does EXCEPTION_ACCESS_VIOLATION occur

眉间皱痕 提交于 2019-12-06 14:20:32
Hi I know that this error which I'm going to show can't be fixed through code. I just want to know why and how is it caused and I also know its due to JVM trying to access address space of another program. A fatal error has been detected by the Java Runtime Environment: EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6dcd422a, pid=4024, tid=3900 JRE version: 6.0_14-b08 Java VM: Java HotSpot(TM) Server VM (14.0-b16 mixed mode windows-x86 ) Problematic frame: V [jvm.dll+0x17422a] An error report file with more information is saved as: C:\PServer\server\bin\hs_err_pid4024.log If you would like to

SIGSEGV within std::sort, how to narrow it down

一个人想着一个人 提交于 2019-12-06 13:51:59
This is a related post to this one as it deals with the same program, but i now implemented it iterative and not recursive anymore, but I still get SIGSEGV (but later) while running the program. I did some other changes to my program to narrow it down, and I figured that changing a vector of objects, to a vector of ptr to the objects on the heap does give me some extra rounds (about 200), but still crashes. I suggest that somehow my memory to save variables within the program gets exhausted, but as I dump the stacksize of the program: rlimit rlim; getrlimit(RLIMIT_STACK,&rlim); std::cout <<

Executing shellcode stored in environment variable using buffer overflow

我与影子孤独终老i 提交于 2019-12-06 13:47:08
问题 I'm using the code below to try to execute some shellcode stored in an environment variable by overflowing the searchstring variable so that the return address of main contains the address of the anvironment variable. However, I get a segmentation fault before the printf command. #include <stdio.h> #include <string.h> void main(int argc, char *argv[]){ char searchstring[100]; if(argc > 1) strcpy(searchstring, argv[1]); else // otherwise searchstring[0] = 0; printf("Here"); } I compile the