[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::decc

Title:DECC
Notice:General DEC C discussions
Moderator:TLE::D_SMITHNTE
Created:Fri Nov 13 1992
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2212
Total number of notes:11045

2169.0. "bug in compiler ??" by NNTPD::"[email protected]" (mark) Tue Apr 29 1997 12:20

Hope this does not turn up twice tried a moment ago and failed (I thought)
Here goes again :-
	Was at a customer site today wrote this piece of code to take a
hex string from an SNA trace and convert it to ASCII from EBCDIC. When blow me
down looks like I hit a compiler/lib bug. If you look at the attached code
in the function loadhex you will see a printf that outputs lg. lg seems to be
0 each time though this loop. This is not what happens in Digital UNIX or on 
VAX/VMS VAX C  V3.2-044  where as the compiler I'm using at the customer site
with the problem is VAX/VMS DEC C V5.5-002. I looked at the machine listing 
from the customer compiler it looks like it did everything right. It used
R3 to hold the variable the only thing I can guess is that one
of the library routines stomps on R3 (eg DECC$DSSCANF or DECC$DPRINTF)
 I'll be back there tomorrow and single step this by instruction this should
confirm what happens to lg (r3)

	Cheers
		Mark :)

programs available via http://nonull.sno.dec.com/scripts/asc.c

[Posted by WWW Notes gateway]
T.RTitleUserPersonal
Name
DateLines
2169.1not reproduced hereCAIRN::HARRISKevin Harris, dtn 381-2039Tue Apr 29 1997 12:5243
Mark,
	I copied the source (commented out the include of snalu62df.h),
compiled it with V5.5-002 on OVMS on both Alpha and VAX, and I don't see the
problem when I run it:

� cc decc_2169.c

        src.dsc$a_pointer = ebc;
........^
%CC-W-PTRMISMATCH, In this statement, the referenced type of the pointer value "
ebc" is "unsigned char", which is not compatible with "char".
at line number 104 in file C4$:[HARRIS]DECC_2169.C;2

        dst.dsc$a_pointer = asc;
........^
%CC-W-PTRMISMATCH, In this statement, the referenced type of the pointer value "
asc" is "unsigned char", which is not compatible with "char".
at line number 109 in file C4$:[HARRIS]DECC_2169.C;2

        if (!(status & 1)) LIB$SIGNAL(status);
...........................^
%CC-I-IMPLICITFUNC, In this statement, the identifier "LIB$SIGNAL" is implicitly
 declared as a function.
at line number 116 in file C4$:[HARRIS]DECC_2169.C;2
� link decc_2169
%LINK-W-WRNERS, compilation warnings
        in module DECC_2169 file C4$:[HARRIS]DECC_2169.OBJ;2
� asc :== $c4$:[harris]decc_2169.exe;1
� asc 121212
char 12 leng  0
char 12 leng  1
char 12 leng  2

src name ebcdic
12 12 12

src name ascii
Status of asc_ebc = 1
12 12 12

What version of OVMS is the customer running?  Do they have any special link
procedure we should know about?
				-Kevin
2169.2SPECXN::DERAMODan D'EramoTue Apr 29 1997 13:5536
        unsigned short loadhex(s, d)
        char	*s;
        unsigned char d[];
        {
        	unsigned char j;
        	unsigned short lg;
        
        	lg = 0;
        	s = spanc(s);
        	while ( *s) {
        		sscanf(s, "%2x", &j);
        		s = s + 2;
        		d[lg] = j;
        		printf("char %2x leng  %d\n", d[lg], lg);
        		lg = lg + 1;
        		s = spanc(s);
        	}
        	d[lg] = '\0';
        	lg = lg + 1;
        	return(lg);
        }
        
        
        You can't declare j to be an unsigned char there, because you
        are passing its address to sscanf with a format specifier "%2x"
        that requires the corresponding argument to be a "pointer to
        unsigned int".
        
        I.e., every call to sscanf in the loop is writing sizeof(unsigned int)
        bytes through &j, but sizeof j is just 1.  Depending on where
        j and lg are placed in memory, the call to sscanf might overwrite
        the value of lg.
        
        Try changing the declaration of j to be unsigned int.
        
        Dan
2169.3more infoNNTPD::"[email protected]"markTue Apr 29 1997 20:2317
The customer is running on a VAX  OVMS 6.2 
I do include that snalu header and link as

link	prog,lu62/opt

where lu62.opt has
sys$share:snalu62h.exe <- or what ever the name is I'll be back there
shortly and verify with an instruction step what happens at this site and
report back here to night my time.

	Cheers
		Mark :)

ps.
	depending on what I find I will get a copy of the binary asc.exe 
from the site and try it else where.
[Posted by WWW Notes gateway]
2169.4interestingNNTPD::&quot;[email protected]&quot;markTue Apr 29 1997 20:2913
Interesting idea about the unsigned short and sscanf I will look at this.
However the machine list showed that lg was held in r3 and was never temp
outside of the register set so I don't see how sscanf could ever over write
this one, except that maybe sscanf manages to write over the saved r3 on
its call frame hmm.
	The other problem is that it works on Unix and works on an old VAXC
and as reported in reply 1

	I'll update this note again this evening my time.

	Cheers
		Mark :)
[Posted by WWW Notes gateway]
2169.5updatlooks like me and the sscanfNNTPD::&quot;[email protected]&quot;markWed Apr 30 1997 06:1212
The tricky thing was that cc/noopt fails because it used the stack to hold lg
which was adj to the auto variable j which was unsigned byte and had a long
written by sscanf where as /opt used a register for lg and so did not cop it
from
sscanf.
	I had a listing from yesterday showing the use of a register for lg 
which appeared to be failing. I must just be confused. 
	Thanks for the correct spot on sscanf and short/byte destination.

	Cheers
		Mark :)
[Posted by WWW Notes gateway]