Thursday, July 9, 2009

Error Error on the Lappy, You make the debugger happy

This blog is dedicated to random errors I witness as my career progresses and the solutions I found for them, if any.

1: Wamp server doesn't work on Vista:

Date: 07/09/2009
Symptoms: browsing to localhost returns 404 (Firefox stays white though)
Reason: Port conflicts with other applications.
Solution: Exit AVG and skype and try to put your wamp server online again. Worked for me.

2. Google Friend Connect widget on a blog crashes Internet Explorer.

Date: 07/14/2009
Symptoms: Internet Explorer crashes and would not open your blog. Case of my blog
Reason: IE doesn't read your HTML one line at a time, but all at once. Therefore the ending tag problem with Friend Connect widget causes IE to crash.
Solution: No Solution yet. Temporary workaround is to move the Friend Connect feature at the end of your widgets (footer).
P.S. If you faced a nasty error recently, you would want to share it with us. Please leave a comment with the problem and your solution.

3. A thread keeps waiting on a barrier

Symptoms: You have a thread which would not move forward from a barrier.
Reason: The barrier is not properly initialized. In most research projects if during initialization you used if.. statement chances are more that you have nested if.. which would not work as you expect.
e.g. see this
if (pthread_barrier_init(&barrier1))
#ifdef HDEBUG
fprintf(stdout,"There were errors initializing barrier 1");
if (pthread_barrier_init(&barrier2))
#ifdef HDEBUG
fprintf(stdout,"There were errors initializing barrier 2");
int somevar = 20;

You see, everything looks good but when you run your code without print statements above two statements are like nested "if" statements.

Solution: remove the #ifdef statements as this is not needed if you are using "if" while initializing.

4: printf prints structure variables together

Date: 08/29/2009
Symptoms: instead of printing value of just one member variable of a structure printf prints additional data from other member variables
Reason: The way C handles strings.
Solution: Make sure there is enough room for \0 at the end of your data values. I was storing an IP address in a string. The length of IP address was exactly equal to array size therefore C couldn't store "\0" at the end of that variable and hence it printed all of them together. I felt like kicking my back when I found this solution.

5: using malloc to assign memory to structure

Date: 10/07/2009
Symptoms: The structure pointer (mine was 3D) doesn't get enough memory as expected. Throws segmentation fault after a limit (it was 14 in my case)
Reason: Returned pointer's casting
Solution: I was assigning memory to a structure pointer by using malloc. I actually had a wrapper for malloc which used to return a void pointer (void *) and caught memory allocation errors. Therefore, I used my function to allocate memory and casted the pointer to my structure type. Sounds good, Looks good but it is not. What happens here is that the wrapper returns a void pointer which I casted again to a structure pointer. I am not sure exactly why I could not access the memory location mystruct[14][0]. Then I changed my wrapper function to allocate memory to a local variable to the wrapper and check for allocations time errors, if everything goes fine free that local variable and return a malloc call. Something like
int size;
return malloc(size)
That solved it for me.

No comments:

Post a Comment