ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have two libraries: one with a linked list of a pointer of structs and its operations, and the other with a xmlParser that fills the linked list.
An example of the xml that is going to be read has the following form:
I have checked that the xml parser is ok, my problem is filling the data structure, I don't understand why it fails because there isn't any error message, but in the call updateParams(ps, cur_node); it stops working.
Thanks in advance.
Please use [code] tags to enclose any future code, it will make it far more readable.
There's a link in my signature which describes how to do this.
struct Car contains four pointers.
When you allocate a struct Car, it allocates the size required for those pointers, but does not initiate them, nor does it allocate space for each of those attributes. This is why you have one error.
Thanks, Rtmistler, but I don't find the link "struct Car contains four pointers", could you send me the link? I am not sure what I have to do.
Well you seemed to have found out how to place code in the proper tags. Thank you for editing.
Unsure if you feel there was some other link. My comment was that struct Car contains four pointers. Here is a cut/paste of the code you posted containing that structure:
This structure contains four pointers. Therefore when you allocate space for this structure, you only allocate space for the four pointers and not space for the xmlChar strings which they are to contain.
When I allocate space for this structure I use this line of code:
struct Car* new_node = (struct Car*) malloc(sizeof(struct Car));
Car already includes four pointers to xmlChar, and a pointer to a xmlChar is a xmlChar string. I am not sure what you mean.
Perhaps I am incorrectly focusing on that and thinking it becomes an error.
Yes. A pointer to an xmlChar is a pointer to a string.
However, a Non-Allocated string.
When you allocate your structure, you solely allocate the pointers alone and not the memory which the pointers are supposed to contain.
Nor are you initializing these pointers.
Is an xmlGetProp() call returning the value of a valid string that is already allocated? If so, then my concerns are unwarranted, and you are only assigning valid values to these pointers.
Therefore what else can go wrong within updateParams()?
Have you verified that the passing argument 'ps' is a valid address?
Is cur_node a valid address?
Have you verified that the call to malloc() worked correctly?
What possible error returns could you get from xmlGetProp()?
Yes, I have checked xmlGetProp return a valid xmlChar*, not an error. I have check that the new_node contains the parameters of the car (in this case model "Motiv", description "city car", currency "euros" and price "30000").
When I debug updateParams it stops working in the following line of code:
ps->params = new_node;
How I can verify ps is a valid address?
cur_node is a valid address and it contains the xmlNode* with the content of the xml file.
Sorry to be so late getting into the discussion here, and thanks RT for carrying the ball this far!
@tarika - You need to be more complete and precise in telling us exactly what this entails...
Quote:
I have debugged with Eclipse line by line and in this line it stops.
If as asked by rtmistler you are single stepping through the code, and it fails at this line, then have you checked the pointers and variables individually immediately before it "stops"? And what do you mean it stops - does the program just exit "normally", directly from that line? How so? Does it return any error messages or status indication at all?
We want to help, but only you are sitting at the compiler and it is you who must debug the code. We can offer suggestions of methods for troubleshooting it, but we must know what is actually happening - only you can tell us that!
Please pause and consider how best to explain to us how you are compiling and running the code, and what exactly is happening that makes you think this line of code is responsible. And if you are certain that this line of code is responsible then tell us exactly what you have done to verify all the pointers and data state immediately before it fails. Please do so with actual results of your tests, as opposed to simply saying yes they are all OK.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.