You are allocating memory that is one byte too short. Your calculations are for the length of the data between e.g. “Subject:” and “Content:” but do not take into account the need for a null terminator in the string. Then when you manually add the null terminator you are invoking undefined behaviour by writing past the end of the array.
Changing your code to the following should fix it.
char* messageSubject = malloc(cPtr - sPtr - strlen("Subject:") + 1) char* messageContent = malloc(strlen(cPtr + strlen("Content:")) + 1)
You also do not show the code in the “…” section, so you may have an unterminated string in there that if it is being processed by the string library routines could cause problems.
Related Posts:
- Visual Studio debugger error: Unable to start program Specified file cannot be found
- How to fix inconsistent line endings for whole VS solution?
- Convert C++ program into assembly
- How to use execvp()
- How to use execvp() to execute a command
- How does strtok() split the string into tokens in C?
- What is *(uint32_t*)?
- what is Segmentation fault (core dumped)? [duplicate]
- How to convert an int to string in C?
- How to print in C
- What is newline character — ‘\n’
- Why does ENOENT mean “No such file or directory”?
- What does the question mark character (‘?’) mean?
- makefile:4: *** missing separator. Stop
- C Linking Error: undefined reference to ‘main’
- Undefined reference to pthread_create
- What is Bit Masking?
- What are .a and .so files?
- What is the C version of RMI
- How to convert an int to string in C?
- How do I use extern to share variables between source files?
- Cannot assign requested address – possible causes?
- error: called object is not a function or function pointer
- Is there any format specifier of bool in C?
- how to open an mp3 file with c
- munmap_chunk(): invalid pointer
- No Symbol Table using GDB on Compiled Programs
- What is char ** in C?
- What is the difference between a static and const variable?
- What is a bus error? Is it different from a segmentation fault?
- unsigned int vs. size_t
- Get the current time in C
- error: expected primary-expression before ‘)’ token (C)
- Bitwise operation |= in C
- Going through a text file line by line in C
- What is activation record in the context of C and C++?
- Get text from user input using C
- How do I lowercase a string in C?
- Fastest way to check if a file exist using standard C++/C++11,14,17/C?
- warning: expression result unused
- Why is volatile needed in C?
- error: indirection requires pointer operand (‘int’ invalid)
- What is the difference between exit(0) and exit(1) in C?
- Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) standard C memory issue
- push_back vs emplace_back
- Visual C++ executable and missing MSVCR100d.dll
- How to print a char array in C through printf?
- How to clear all the elements of array in C?
- Is the sizeof(some pointer) always equal to four?
- 2D array vs array of arrays
- Sign extend a nine-bit number in C
- How to create an array of strings in C?
- Already defined in .obj – no double inclusions
- C char* to int conversion
- expected expression before ‘{‘ token
- C Vector/ArrayList/LinkedList
- How can I get the list of files in a directory using C or C++?
- What are the different versions of exec used for in C and C++?
- Portable way to check if directory exists [Windows/Linux, C]
- This project references NuGet package(s) that are missing on this computer
- C++ – include unistd.h: why not cunistd?
- Simple way to check if a string contains another string in C?
- How to convert integer to char in C?
- Regular expressions in C: examples?
- What’s the difference between * and & in C?
- Writing a simple shell in C using fork/execvp
- Difference between pic Vs pie
- What is the difference between array and enum in C ?
- How would one write object-oriented code in C?
- What’s the meaning of exception code “EXC_I386_GPFLT”?
- C: pointer to array of pointers to structures (allocation/deallocation issues)
- gcc -g :what will happen
- How to find EOF through fscanf?
- What are .axf files?
- Can’t understand the working of getint() in C as per K&R
- printf format specifiers for uint32_t and size_t
- What do the dup() and dup2() systems really do?
- How to remove first character from C-string?
- What is an simple example of copy_from_user
- How do you implement a class in C?
- What is `S_ISREG()`, and what does it do?
- typedef struct pointer definition
- Representing EOF in C code?
- Math constant PI value in C
- The code does not execute properly. Try to figure out why
- ld.exe: cannot open output file … : Permission denied
- How to read from input until newline is found using scanf()?
- What is char ** in C? [duplicate]
- Fatal error: iostream: No such file or directory in compiling C program using GCC
- What tools are there for functional programming in C?
- typedef fixed length array
- Invalid write of size 1
- How to solve static declaration follows non-static declaration in GCC C code?
- realloc(): invalid next size when reallocating to make space for strcat on char *
- gdb: No symbol “i” in current context
- meaning of &variable (passed to function)
- Whats the difference between UInt8 and uint8_t
- How to Compare 2 Character Arrays [duplicate]
- Example of realpath function in C
- How to use redirection in C for file input