Member Avatar for xcr

Hello all,

I turn once again to the wisdom of the internet:

I have attached my two files to this post as to not use up a whole lot of space. The program is a mock "assembler" it takes mock assembly code and turns it into a file with hex values that represent the commands.

What I have compiles fine, but when I try to run it against the input.s file attached I get a segfault. Running the program through valgrind, I get 8 entries of "Conditional jump or move depends on uninitialised value(s)" but each say that the "Uninitialised value was created by a stack allocation" so I don't think that there is anything that I can do.

Can someone take a look at my code and tell me where I went wrong?

Many thanks,
~xcr

Recommended Answers

All 3 Replies

>>while (fgets(line, MAX_BUFFER, infile) != NULL){

line is a NULL pointer. You must allocate memory for it before you can use it here.
Add this somewhere before that loop line = malloc(MAX_BUFFER);

Member Avatar for xcr

Thank you for your reply, I mad the change that you suggested, but now I am having the problem that the fprintf statements don't write anything to the output file. I have modified my code with a bunch of printfs to try and debug, and what I see is that the operations enter the switch statment and sscanf returns that it didn't scan any fields in.

I did modify the format of the input files to be tab delimited and modified the sscanf for tabs.

I am completely baffled as to why sscanf returns 0 for each and every line.

My modified code is attached.

You have the same problem with other char* variables that you had with line. Just how do you expect sscanf() to work if those are unallocated buffers? sscanf() doesn't allocate the memory, that is your responsibility.

You need to proofread your who program very carefully and make all corrections like that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.