Questions tagged [realloc]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2
votes
2answers
1k views

What will realloc() do if the contiguous memory location is already occupied?

Consider- char* name1 = malloc(4 * sizeof(char)); name1 = "Mike"; Now if i want to put "Mike Smith" in the same string "name1", I need 6 more bytes of memory (one for the space and 5 for "Smith". ...
0
votes
1answer
33 views

How is my (custom) program leaking memory? I am preparing myself for pset5

I'm trying to understand how memory allocation and pointers work, since i find pset5 overwhelming. I made a simple program that reads characters from an array, and let them be written into both a new ...
0
votes
1answer
162 views

In pset6 server.c, does using realloc() reset the file pointer for fread()?

The following was my load() function for pset6 server.c bool load(FILE* file, BYTE** content, size_t* length) { size_t count = 0; BYTE* file_char = malloc(sizeof(BYTE)); while (...
0
votes
1answer
123 views

realloc and length in load(), server.c

I need help with load() in server.c. This is a follow-up to the other question, except now I'll post the updated code and make it a bit more specific. When I tested the server after implemented ...
0
votes
1answer
458 views

pset6 parse function: Invalid read of size 1

I'm having trouble with allocating memory correctly. p is a pointer that I intended to point to method, target, then http switching to the next one after each space is found. Then I thought I'd be ...
0
votes
1answer
510 views

pset6 - load(), realloc() and 'invalid next size' error

I am stucked at the load() function. This line : newBufferSize = bufferSize * (*length); gives me the following error: realloc(): invalid next size: 0x0000000000607be Then the process was aborted. ...