chris@mimsy.UUCP (Chris Torek) (10/07/88)
In article <660020@hpclscu.HP.COM> shankar@hpclscu.HP.COM (Shankar Unni) writes: -Re: Expanding the argv array: - -Try: - - argv = (char **) realloc (argv, newsize * sizeof (char *)) - /* newsize is the size of your expanded argv array */ - for (ctr = OLDargc; ctr < newsize; ctr++) - argv[ctr] = (char *) 0; - /* now append arguments to your heart's content.. */ - - /* NO COMMENTS ABOUT PASCAL'ish CODING!!! :-) */ There is nothing particularly Pascal-ish about this. It is, however, wrong. argv[] is not allocated by malloc(), or not guaranteed to be so allocated, and therefore it is wrong to call realloc on it. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris
shankar@hpclscu.HP.COM (Shankar Unni) (10/08/88)
> There is nothing particularly Pascal-ish about this. It is, however, > wrong. argv[] is not allocated by malloc(), or not guaranteed to be so > allocated, and therefore it is wrong to call realloc on it. Whoops! foot-in-mouth. I remember now (sound of slapping on forehead :-))! Well, go on, use calloc instead and copy over the existing argv array.. -- Shankar