[Prev][Next][Index]

ScanBcast bug in pC++ (common.h)



Hi,

Recently I noticed some strange behavior of fscanf("%s", ...) on CM-5.
I looked into the file "common.h" and noticed the following code
in the function ScanBcast():

----------------------------------------------------------
/* chars and strings */
 case 4: z7 = va_arg(ap, char *);
   if((c == 's') || (c == '[')){
	   if(pcxx_NodeNumber() == 0){
		   len = strlen(z7);
		         ^^^^^^^^^^^^^^^^^^^
		   pcxx_BroadcastBytes(0, (int) sizeof( int), (void *) &len);
		   pcxx_BroadcastBytes(0, len, (void *) z7);
	   }
	   else{
		   pcxx_BroadcastBytes(1, (int) sizeof( int), (void *) &len);
		   pcxx_BroadcastBytes(1, len, (void *) z7);
	   }
   }
   else{	 ...
----------------------------------------------------------

Since scanf("%s", foo) is supposed to store a '\0' at the end of
foo, shouldn't the above expression for len be
	len = strlen(z7)+1;	????

At least, this is how I had to change it in my code in order for 
scanf (or fscanf) to work correctly.

	--Vladimir

P.S. Once we are talking about fscanf... Did anybody react to my
   note a couple weeks ago to the effect that the return value
   of pC++ fscanf is garbage, rather than the number of items read?
   You know, there are some old-fashioned people, who are used
   to heeding to the lint's warning "The return value of scanf is not used!",
   and actually do check it! :-)