segmentation-fault

Segmentation fault when casting int to char in C

跟風遠走 提交于 2021-02-10 10:23:00
问题 I have a very simple C program. In main, I have this operation: int main(){ int theNumber = 9009; printf("%s", (char *)theNumber); } And when I run it, it gives me a seg fault. Any idea why? Am I doing this wrong? Expected Output This code should convert theNumber to a string and then print it. So the output would be: 9009 Actual Output A segmentation fault. 回答1: This is trying to print whatever is found at the address 9009 . Seeing as the operating system is not giving your program access to

Invalid write of size 8, C Valgrind, string arrays

房东的猫 提交于 2021-02-08 15:52:41
问题 I have been using both valgrind and gdb and I can not quite figure out what the problem is. It hops around too much for me to really trace it down in gdb, and in valgrind I don't have enough information. Here is my makeargv function, which is putting strings outputted from strtok() into arrays. makeargv is called from the below parse function. I'm not sure where I'm going wrong. I would really appreciate the help :D. Just an FYI I'm really new to all this malloc'ing and don't really

dynamic allocation of array of pointers

无人久伴 提交于 2021-02-08 15:44:08
问题 The following code gives a segmentation fault. I am not able to figure out as to why. Please see.. #include <stdio.h> #include <stdlib.h> int main() { int **ptr; int *val; int x = 7; val = &x; *ptr = (int *)malloc(10 * sizeof (*val)); *ptr[0] = *val; printf("%d\n", *ptr[0] ); return 0; } on debugging with gdb, it says: Program received signal SIGSEGV, Segmentation fault. 0x0804843f in main () at temp.c:10 *ptr = (int *)malloc(10 * sizeof (*val)); Any help regarding the matter is appreciated.

shellcode buffer overflow -SegFault

时光毁灭记忆、已成空白 提交于 2021-02-08 11:15:10
问题 I'm trying to run this shellcode but I keep getting segmentation fault /* call_shellcode.c */ /*A program that creates a file containing code for launching shell*/ #include <stdlib.h> #include <stdio.h> #include <string.h> const char code[] = "\x31\xc0" /* Line 1: xorl %eax,%eax */ "\x50" /* Line 2: pushl %eax */ "\x68""//sh" /* Line 3: pushl $0x68732f2f */ "\x68""/bin" /* Line 4: pushl $0x6e69622f */ "\x89\xe3" /* Line 5: movl %esp,%ebx */ "\x50" /* Line 6: pushl %eax */ "\x53" /* Line 7:

shellcode buffer overflow -SegFault

南楼画角 提交于 2021-02-08 11:12:44
问题 I'm trying to run this shellcode but I keep getting segmentation fault /* call_shellcode.c */ /*A program that creates a file containing code for launching shell*/ #include <stdlib.h> #include <stdio.h> #include <string.h> const char code[] = "\x31\xc0" /* Line 1: xorl %eax,%eax */ "\x50" /* Line 2: pushl %eax */ "\x68""//sh" /* Line 3: pushl $0x68732f2f */ "\x68""/bin" /* Line 4: pushl $0x6e69622f */ "\x89\xe3" /* Line 5: movl %esp,%ebx */ "\x50" /* Line 6: pushl %eax */ "\x53" /* Line 7:

Isnt Segmentation fault the same as the smashing the stack?

孤者浪人 提交于 2021-02-08 08:42:34
问题 As a consequence of an programming error we get segmentation faults . But as a necessary tool we try the same thing but the kernel detects it as smashing the stack . How exactly does the kernel see the difference ? 回答1: Briefly, no. Segmentation faults are when the kernel is able to detect an invalid memory access and then kills the process. Some invalid memory accesses cannot be detected by the kernel, and stack overflows are built on these. However, stack overflows can be detected by the

C structs: segmentation fault

泪湿孤枕 提交于 2021-02-08 05:41:47
问题 Quick question about structs: struct xint { int number; char string[12]; }; int main(int argc, char *argv[]) { struct xint offsets, *poffsets; poffsets=&offsets; FILE * pFile = fopen("file","rb"); fread(poffsets,1,16,pFile); printf("Number %d\nString %s\n",offsets.number,offsets.string); } I get this output Number 12345 Segmentation fault I know I've probably done something wrong with structures and pointers and memory allocation. Thanks in advance :) 回答1: Your problem is you're directly

QPainter.drawText() SIGSEGV Segmentation fault

爷,独闯天下 提交于 2021-02-07 14:28:34
问题 I'm trying to print a simple text message in a thermal printer through Qt5 printing methods. #include <QCoreApplication> #include <QDebug> #include <QtPrintSupport/QPrinterInfo> #include <QtPrintSupport/QPrinter> #include <QtGui/QPainter> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QPrinter printer(QPrinter::ScreenResolution); QPainter painter; painter.begin(&printer); painter.setFont(QFont("Tahoma",8)); painter.drawText(0,0,"Test"); painter.end(); return a.exec(); }

Segmentation fault (core dumped) on tf.Session()

风流意气都作罢 提交于 2021-02-07 11:54:06
问题 I am new with TensorFlow. I just installed TensorFlow and to test the installation, I tried the following code and as soon as I initiate the TF Session, I am getting the Segmentation fault (core dumped) error. bafhf@remote-server:~$ python Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) [GCC 7.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf /home/bafhf/anaconda3/envs/ismll/lib/python3.6/site-packages/h5py/__init__

How to identify what is causing the Segmentation fault

两盒软妹~` 提交于 2021-02-05 09:42:44
问题 My code's aim is to take in 2 command line arguments (inclusive of programme name), and to print out responses as shown based on the given 2nd command line argument. If the command line argument is an integer, the user's input is accepted or "Success"and if it as anything else (e.g. a string or more than one command line argument), it will be Null and the error message will be shown. This is for CS50 caesar for those who are familiar My Code is as follows: #include <stdio.h> #include <cs50.h>