segmentation-fault

Dedenting function in QPlainTextEdit causes segfault if last line is involved

a 夏天 提交于 2019-12-13 02:08:11
问题 I'm working on a source code editor that should have smart indent/dedent behaviour. However, my dedenting method seems to be causing a segmentation fault. I'd be very pleased if someone could work out why. Here's a minimal example: #!/usr/bin/env python import sip sip.setapi('QString', 2) sip.setapi('QVariant', 2) from PyQt4 import QtGui from PyQt4.QtCore import Qt class Editor(QtGui.QPlainTextEdit): def keyPressEvent(self, event): key = event.key() if key == Qt.Key_Backtab: cursor = self

Reading from file of undefined length, storing in array, segmentation fault

做~自己de王妃 提交于 2019-12-13 02:01:47
问题 I want to open a file, read its content and store it in an array using C code. I did it on my Windows laptop and it works but when i try the code on my Raspberrypi i get segmentation faults. I've been trying for a while to debugm I'm quite new to C so I'm having trouble finding what I did wrong. char *readFile(char *fileName) { FILE *ptr_file; char *ptr_data; int n = 0; char c; ptr_file = fopen(fileName, "r"); if(ptr_file == NULL) { perror("File could not be opened.\n"); exit(EXIT_FAILURE); }

boost::asio triggers a sigsegv in std::type_info::operator==

匆匆过客 提交于 2019-12-13 00:29:41
问题 So, I've got an application that uses boost::asio. Due to complexity of the project, I cannot share it's source code, sadly :( The application uses boost's asio lib to create some webservices. When attempting to use it, however, there's a sigsegv in std::type_info::operator==, which, as I'm aware, should rather work. (gdb) backtrace #0 0x0000000000457b79 in std::type_info::operator== ( this=0x7ffff6dadf61 <typeinfo for boost::asio::detail::typeid_wrapper<boost::asio::deadline_timer_service

Reading from stdin using fgets()

梦想与她 提交于 2019-12-13 00:06:56
问题 I'm new to C programming and I'm currently trying to read a line from stdin using fgets(), but I'm having trouble with memory allocation since I'm using a char* to point to the string I want to read. When I execute the file it reports a segmentation fault. This is the function I'm using: char *read_line(char *line){ printf("%s",PROMPT); line = (char*)malloc(sizeof(char)*500); fgets(line,sizeof(line),stdin); printf("%s","pasa el fgets"); return line; } And my main: void main(){ char line0;

C: Merge-Sort of an array with uneven number of elements

不羁的心 提交于 2019-12-12 22:30:49
问题 I've been working on an assignment for my Procedural Programming class where we are provided with a merge-sort program that does not function completely. It performs a merge-sort on arrays with an even number of integers, but throws a segmentation fault with an odd number of integers. I understand how the sorting works, and that the segmentation fault is being thrown because the odd number is causing the segmentation fault because the array is being over-filled somehow. I also understand that

Segfault when invlpg instruction is called

 ̄綄美尐妖づ 提交于 2019-12-12 21:40:28
问题 I am trying to implement tlb flush function. For flushing I use INVLPG instruction, but unfortunately it always cause segmentation fault. Could you help me with this issue? Here is the code: #include "stdlib.h" inline void tlb_flush_entry(int *m) { asm volatile ("invlpg %0"::"m"(*m):"memory"); } int main(int argc, char **argv) { int *memory = (int *)malloc(100); tlb_flush_entry(memory); } 回答1: The SIGSEGV happens because INVLPG is a privileged instruction and can only be called out of kernel

The Impossible Happened! What does this mean?

和自甴很熟 提交于 2019-12-12 21:12:00
问题 I have experienced an interesting runtime error. I assume it is some sort of memory leak. I wrote the following program: C Code: #include <gmp.h> #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #define PRECISION 4096 #define DECIMAL_POINT 1 #define NULL_TERMINATOR 1 void gatherSquares(const uint32_t limit, uint32_t ** const arr, uint32_t * const count); uint32_t inList(const uint32_t n, const uint32_t * const arr, const uint32_t count); void print_help(const

SSB dbgen Linux - Segmentation Fault

醉酒当歌 提交于 2019-12-12 19:19:13
问题 I am trying to generate SSB tables and getting Segmentation fault (core dumped) error. During "make" I get a lot of warnings due to variable types but it seems to compile with success. I do understand that segmentation fault is due to the wrong memory access but I have not changed anything except for 4 makefile options. Make file has: CC = gcc DATABASE = DB2 MACHINE = LINUX WORKLOAD = SSBM I have already downloaded several generatos from different websites but I always get same error. I am

GCC: Segmentation fault and debugging program that only crashes when optimized

半城伤御伤魂 提交于 2019-12-12 18:29:44
问题 This is a follow up to thread: C: Segmentation fault and maybe GDB is lying to me I have a program that compiles fine with -O0 but segfaults with -O1, -O2, -O3 and Ofast. It seems the stack somehow gets corrupted at some point but I can't figure out why or where. First, here's part of the struct that I'm using. It's in a header file: typedef struct { GLuint nsHandle; } OGL_STATE_T; Here's the relevant watered down part of the main file: void init(OGL_STATE_T *state) { printf("init: %p\n",

Why can't I assign values to pointers?

一世执手 提交于 2019-12-12 18:19:43
问题 After reading the faq's and everything else I can find, I'm still confused. If I have a char pointer that is initialised in this fashion: char *s = "Hello world!" The string is in read-only memory and I cannot change it like this: *s = 'W'; to make "Wello world!". This I understand, but I can't, for the life of me, understand how to make it NOT read-only. Do I have to use an array instead of a pointer? Like here? This is my code: char *s = str; char *e = s; while (*e != '\0') e++; e--; char