My library is failing and I cannot figure out why...
NOTE: Feel free to laugh at me at any time, just don't flame me please :)
Ok, its been a while since my last (first) thread here. And back then I was really naive. I probably still am, but I can't figure this out. I have searched here and on google, have looked in a couple of publications for help, but I am still stuck.
I am writing this program that will take database exports and backups and generate reports from it. This library is the first part I decided to work on because, well, it just was. Remember, I in no way claim to know what the hell I am doing...
First off, the problem I am having is that my library is failing when it tries to read a part of an object from memory (I think). The program just exits, no seg-fault, no abnormal termination... I do see a memory leak when I use memprof on it, but I am not sure what to do to avoid it. Sooooo.... without further ado, here is my class declaration: (this is the entire header file...)
Code:
// libpstate.h
struct S_prog_error {
char *curblock;
char *calblock;
char *currargs;
char *currfunc;
char *errortxt;
char *errorarg;
char *errortyp;
unsigned int errcount;
};
struct S_prog_state {
char *library;
char *module;
char *function;
char *caller;
char *argument;
};
class C_prog_state {
public:
S_prog_state *psp[];
S_prog_error *pep[];
C_prog_state ( int num_of_states, C_prog_state *old );
~C_prog_state () {};
C_prog_state *ptt;
int states;
int write_state ( int state_index, char *state_str[5] );
int write_error ( int state_index, char *error_str[7] );
int read_states ( int state_index, char *ps [ 5 ] );
int read_errors ( int state_index, char *pe [ 7 ]);
int print_error ( int state_index );
int print_state ( int state_index );
int passer ( C_prog_state *ptr );
};
I don't know whether or not the problem lies there, but I can't post my library source just yet.... I have to put comments in so its readable... Let me know which definitions to post also so I don't have to post the whole thing (but I will if I have to)
Thanks everyone
(look for commented code in an hour or three)
OK here it is finally....Terribly sorry for the wait
And may the almighty moderators please please please forgive me for not being prepared when I should have been, for being generally inane, and for posting so many times just to get all the information regarding my question out in the open... Please don't smack me too hard. ;)
Lets assume for the moment that I want to use char* instead of std::strings for an undisclosed reason. Just show me where I am doing something other than what is needed.
I don't know whether or not I should code the whole thing or add it as an attachment.... I guess when in doubt, I shall do the latter. (it is all of 236 lines)
On a side note, I have made a minor change to the header I already posted that makes things a little simpler in a small part of libpstate.cpp.
in S_prog_error, the variable errcount has been removed and now appears in the body of the C_prog_state class....
in libpstate.h:
in S_prog_error {}:
Code:
unsigned int errcount;
has been removed.
and in C_prog_state {}:
Code:
unsigned int errcount;
has been added.
Don't worry, I am not going to keep modifying the thing until I have a strategy to fix my issues. It still compiles and behaves the same as before.
Speaking of compiling..... my Makefile is here too:
Code:
libpstatetest: libpstatetest.cpp
g++ -O3 -Wall -c -o libpstate.o libpstate.cpp
g++ -O3 -Wall -o libpstatetest libpstate.o libpstatetest.cpp
I get no errors at compile time, which would be the case if I have a bad memory allocation problem... (I think???) Anyhow here is the output I get when I run the test program:
[root@MYBOX libpstate]# ./libpstatetest
Program State Information: (State Level: 0)
Current library:
Current module: [root@MYBOX libpstate]#
I know I am doing many things wrongly and many more wierdly. But this is how I learn (by doing things wrong) and, amazing as it is, it is how I keep myself interested in learning (by doing things wierdly).
I am also posting the test program I wrote to test this library. It is small so I will just code it.
Code:
// libpstatetest.cpp
#include "libpstate.h"
#include <iostream>
#include <string>
using namespace std;
int main () {
C_prog_state cps = C_prog_state ( 1, (C_prog_state*)NULL );
cps.print_state ( 0 ); // This is the function call in which the prog
// abruptly stops with no appearent reason.
cps.print_error ( 0 );
return 0;
}
There is also an alternate library source file that fails at a different place, but while dealing with the same peice of memory. I will not modify the Makefile included in the text of this post, but the Makefile I will upload will be able to "make libpstatetest.alt" as well as "libpstatetest" for both implementations..
I will attach all source files as well as the Makefile. I will append a .txt to the end of the Makefile so it will let me upload it. I wish I could upload a gzipped tarball containing everything, but oh well... (Keep in mind, libpstate.alt.cpp does not have comments in it)
Thanks again, and once more, I apologize profusely for my delays and poor skills. At least I am working on improving them, utilyzing my entire budget of negative money ;)
Look forward to hearing from you guys soon.
Have a good weekend as well... My internet connection is flaky at home and I may not be able to log in to check the status of this. But I will be back Monday.