Sponsored Content
Top Forums Programming SIGSEGV when allocate a certain size Post 302580156 by Corona688 on Wednesday 7th of December 2011 05:58:34 PM
Old 12-07-2011
Quote:
Originally Posted by migurus
The code in red was not there, so for a line that would start with # comment the code tries to access buf[-1]. How peculiar that the error lingered there and was never causing troubles before my stack shifted as a result of arrays size growth.
Interesting.

Negative array indexes aren't specifically wrong per se, since you're allowed to do

Code:
int array[5]={1,2,3,4,5};
int *x=array+3;
x[-1]=2;
printf("%d\n", array[2]);

It's certainly not encouraged though.

Nothing to do with your stack though -- malloc() doesn't come from there.

Making malloc() larger may have ended up putting the block into a different heap, so the crashing code was more likely to hit invalid memory than to harmlessly nudge the end of your big array when loading a config file. Or could have been something else entirely. Difficult to tell.
 

10 More Discussions You Might Find Interesting

1. Programming

SIGSEGV problem

Hi. Can someone to help me in a segfault problem? I have a big C++ program that crash from time to time because it receive the SIGSEGV signal. So my question is: Can I find, without using gdb or other debugging tools, which line from source code cause that problem? Or if exist some gdb API... (1 Reply)
Discussion started by: vaidac_coder
1 Replies

2. Programming

SIGSEGV, Segmentation fault

Here is my initiating code: #define NUM 20 static struct tab { int count; int use; } tab; int curtab = 0; int tab_create(int tab_count) { curtab++; tab.use = 1; tab.count = tab_count; kprintf("here!"); return curtab; } (2 Replies)
Discussion started by: micmac700
2 Replies

3. Solaris

How to correctly allocate size while creating FileSystem

Hello - I am finding difficulty in creating and allocating correct size to File Systems on solarix x86 box. Please see below contents I followed on screen and in the end It shows that /app file system is created of size 135GB , I wanted it to be 30gb as mentioned during 'format' command in 'Enter... (7 Replies)
Discussion started by: panchpan
7 Replies

4. Programming

SigSegV during stack unwind (AIX)

Hi I am getting a strange segmentation fault during the unwind process. I am trying to throw an object of an Exception class. During the DoThrow (in libC.a) the stack starts growing until a Signal is received. The object thrown is of a class that inherits from a common class, and the signal... (0 Replies)
Discussion started by: barak
0 Replies

5. Programming

problem in SIGSEGV signal handling

i wrote handler for sigsegv such that i can allocate memory for a variable to which sigsegv generated for illlegal acces of memory. my code is #include <signal.h> #include<stdio.h> #include<stdlib.h> #include<string.h> char *j; void segv_handler(int dummy) { j=(char *)malloc(10); ... (4 Replies)
Discussion started by: pavan6754
4 Replies

6. UNIX and Linux Applications

SIGSEGV Signal handling

Hello, Can anybody tell me how can i handle segmentation fault signal, in C code? (2 Replies)
Discussion started by: mustus
2 Replies

7. AIX

Received signal #11, SIGSEGV [default] on AIX 6.1

Hello, One of our customer is getting segmentation fault when he runs his shell script which invokes our executable on AIX 6.1. On AIX 5.3, there were no issues. Here is the truss output. 811242: __loadx(0x0A040000, 0xF0D3A26C, 0x00000000, 0x00000009, 0x00000000) = 0xF026E884... (0 Replies)
Discussion started by: erra_krishna
0 Replies

8. Solaris

sigsegv Fault

I receive a sigsegv failure. I was under the impression that a core file is created everytime a sigsegv occurrs and the process is terminated. I have had two recent occurrances of a core file not being created. Does anyone know why a core file would not be created. (2 Replies)
Discussion started by: amp4cats
2 Replies

9. Shell Programming and Scripting

Error PHP Fatal error: Allowed memory size of 67108864 bytes exhausted(tried to allocate 401 bytes)

While running script I am getting an error like Few lines in data are not being processed. After googling it I came to know that adding such line would give some memory to it ini_set("memory_limit","64M"); my input file size is 1 GB. Is that memory limit is based on RAM we have on... (1 Reply)
Discussion started by: elamurugu
1 Replies

10. UNIX for Advanced & Expert Users

How to create SIGSEGV at particular memory?

Hi I want to create a SIGSEGV when program tries to access one particular area in memory. Is this possible. If so whats the command. (4 Replies)
Discussion started by: jionnet
4 Replies
Ns_Alloc(3aolserver)					   AOLserver Library Procedures 				      Ns_Alloc(3aolserver)

__________________________________________________________________________________________________________________________________________________

NAME
ns_calloc, ns_free, ns_malloc, ns_realloc - Memory allocation functions SYNOPSIS
#include "ns.h" void * ns_calloc(size_t num, size_t esize) void ns_free(void *ptr) void * ns_malloc(size_t size) void * ns_realloc(void *ptr, size_t size) _________________________________________________________________ DESCRIPTION
The AOLserver memory storage allocation code was moved into Tcl core beginning with Tcl 8.4.0. Starting with AOLserver 3.5, these memory allocation functions are wrappers that call Tcl_Alloc and Tcl_Free. Earlier versions of AOLserver used this fast memory storage allocator internally, or the platform's memory allocator depending on how you configured it. The actual amount of memory allocated or freed will be different from the requested amount. This is because the fast memory allocation code pools memory into chunks and manages that memory internally. In addition, the Tcl distribution may be compiled to allocate even more memory which is used internally for diagnostic reasons. Using ns_free to free memory created by routines other than ns_malloc, ns_realloc and ns_calloc will almost certainly result in segmentation faults or undefined behavior. The lowercase and mixed-case versions are identical; the lowercase versions are preferred. ns_calloc(num, esize) Allocates a block of memory that is num * esize large, zeros it, and returns a pointer to the beginning of the memory block or NULL if the operation fails. ns_free(ptr) ns_free() frees the memory space pointed to by ptr. This pointer must have been created with a previous call to ns_malloc(), ns_cal- loc() or ns_realloc(). If ptr is NULL, no operation is performed. ns_free() returns no value. ns_malloc(size) ns_malloc() allocates size bytes and returns a pointer to the allocated memory. The memory is not cleared. The value returned is a pointer to the allocated memory or NULL if the request fails. The memory must be freed by ns_free. ns_realloc(ptr, size) ns_realloc changes the size of the memory block pointed to by ptr to size bytes. The contents will be unchanged to the minimum of the old and new sizes. Newly allocated memory will be uninitialized. If ptr is NULL, the call is equivalent to ns_malloc(size); if size is equal to zero, the call is equivalent to ns_free(ptr). Unless ptr is NULL, it must have been returned by an earlier call to ns_malloc(), ns_calloc() or ns_realloc(). SEE ALSO
Tcl_Alloc(3), Tcl_Free(3) KEYWORDS
memory, allocation AOLserver 4.0 Ns_Alloc(3aolserver)
All times are GMT -4. The time now is 11:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy