Square Galaxy

Tag: c

atoi(getenv(”MYVAR”))

by Jacob on May.28, 2008, under Technical

These are mostly personal notes. I’m not sure if they will make sense to others.

I had a problem with a line of code like this:
int x = atoi(getenv("MYVAR"));

If this line was in daemon-ized code started at init level 2, it would segfault. (I’m not sure if these conditions are necessary, but those were my conditions).

getenv("UNKNOWN_VAR") == NULL
atoi(NULL) should == 0

But for some reason, things were segfaulting. I corrected the problem with:
if (getenv("MYVAR") == NULL) int x = 0;
else int x = atoi(getenv("MYVAR"));

2 Comments :c, linux, programming, Software more...

What bothers you most about this code?

by Jacob on Apr.01, 2008, under Technical

I came across this line of code today, and while I don’t normally hate other people’s coding style, this one has something in it that really bothers me:

i = ((unsigned int)(crcAccum >> 24) ^ *dataBlkPtr++ ) & 0xff;
3 Comments :c, programming, question, Software Engineering more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

 

January 2009
S M T W T F S
« Dec    
 123
45678910
11121314151617
18192021222324
25262728293031