Re: [BUG] Broken code in orb.c



"Momchil 'Velco' Velikov" <velco@fadata.bg> writes:
> Well, the code is just wrong ... here's a patch
> 
> Regards,
> -velco--- orb.c.old	Sat Jan 23 03:23:58 1999
> +++ orb.c	Sat Jan 23 03:25:12 1999
> @@ -306,8 +306,8 @@
>  
>  		ctmp = g_get_home_dir();
>  
> -		buf = alloca(strlen(ctmp) + sizeof("/.orbitrc"));
> -		sprintf(ctmp, "%s/.orbitrc", buf);
> +		buf = alloca(strlen(ctmp) + 9 /* strlen("/.orbitrc") */ + 1 );
> +		sprintf(buf, "%s/.orbitrc", ctmp);
>  		ORBit_rc_load(buf, options);
>  	}

What?...

What's wrong with `sizeof("/.orbitrc")'.  The C compiler is smart
enough to figure out the size occupied by a string literal (and yes,
it also takes into account the trailing \0). 

Can you tell us why you think that this code is wrong.  What compiler
complained?  Did any "bug" go away when you made your change?  Can you
try out a simple C program on your compiler and tell us its output.

	#include <stdio.h>
	int main()
	{
	  printf("%d %d %d %d\n", sizeof(""), sizeof("hello"),
				sizeof(" "), sizeof("world"));
	  return 0;
	}

- Hari
-- 
Raja R Harinath ------------------------------ harinath@cs.umn.edu
"When all else fails, read the instructions."      -- Cahn's Axiom
"Our policy is, when in doubt, do the right thing."   -- Roy L Ash



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]