
kyle-qmail at memoryhole
Mar 5, 2009, 8:58 AM
Post #4 of 4
(1152 views)
Permalink
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday, March 5 at 09:12 PM, quoth Y.K. Choi: >Oh. >Thanks for your correction... > >env.c:56, &environ => environ Okay, line 56 is: if (!alloc_re(&environ,(en + 1) * sizeof(char *),(ea + 1) * sizeof(char*)) So, if I understand you, you're suggesting that it *should be: if (!alloc_re(environ,... right? I can see why you would say that, but let's investigate more closely. What does alloc_re do? Well, it assumes it's been passed an array of pointers (a char**), and what it does is change the size of the first element of that array. So, if it's called on environ, it will change the size of the array pointed to by environ[0], whereas if it's called on &environ, it will instead change the size of the environ array itself (the expression &environ essentially produces a single-element array of pointers to the variable environ---we're resizing (&environ)[0]). Does that make sense? Let's take a moment to examine environ. It is a list of all the environment variables. For example, environ[0] may be the string "SHELL=/bin/sh" and environ[1] may be the string "TZ=US/Eastern", and so on. So what is the env_add() function trying to do? It's trying to ADD an environment variable to the environment. In order to do that, what does it need to do? Obviously, it needs to make the environ array one entry longer, and then put the new environment variable (s, in this case) into that new entry. And resize the environ array is precisely what the env_add() function does does, but it uses the alloc_re() function to do so. So, you're correct that the data types don't match, but the result is the correct behavior. So, it's not a bug, even if it is slightly confusing. It's probably even an intentional choice, to avoid needing to write a function that's identical to alloc_re() but that has different argument types. ~Kyle - -- Arguing with an engineer is like wrestling with a pig in mud, after a while you realize the pig is enjoying it. -- Unknown -----BEGIN PGP SIGNATURE----- Comment: Thank you for using encryption! iEYEARECAAYFAkmwBJgACgkQBkIOoMqOI14IkgCfSFYa1AuefwQBfzZ+4eh3LQ7N HVsAn1NI7GQVAOCpi8UMgiKBycx60AiU =luTE -----END PGP SIGNATURE-----
|