Passing pointers through multiple functions.
Hello,
I'm trying to pass a pointer through multiple layers of functions and then write data to the original memory where the first pointer was allocated but it keeps crashing. Full code is available here. It's not homework just struggling to figure out what I am doing wrong. :) https://github.com/OpenNOP/opennop Example: Code:
struct processor { |
I think you're trying to be too complicated. You can send the address of a pointer.
Code:
unsigned char **pointer_to_a_pointer_to_an_unsigned_char; |
I wrote a sample program and tested it but everything worked. So I might have been focusing on the wrong place in my code to begin with.
Here was my sample program. Code:
#include <stdio.h> |
Off: nowadays we have <inttypes.h> that gives us int8_t and uint8_t, so we don't have to rely on linux-specific types.
|
My particular application is pretty specific to Linux. It possible I could add support BSD by using divert but so far there have been zero requests for that. Thanks for the info seems like a good thing to know.
|
Your code would be much clearer if you consistently refer to e.g. struct record * instead of using void * or __u8 *. This would eliminate the need for typecasting.
For instance, in struct processor, *buffer is properly a pointer to struct record. If you then consistently referred to the structures in the parameter-lists of the various functions, "C" could detect inconsistencies for you. All bets are off when you use typecasting ("C" has no choice but to believe whatever you say is true). |
That makes sense. I should be more consistent in passing structures and try to limit passing arbitrary types as parameters. I assume it's probably ok to typecast inside the function but keep it isolated in the function.
Thanks. I will have a lot of clean to do. :( |
All times are GMT -5. The time now is 12:34 PM. |