Discrepancy in the solaris CC 5.3 and 4.2

P

Pr

Hi -
I have a code that works very well on 4.2, but fails on 5.3.

Here's the description of the problem.

I use 'gperf' generated C++ files in my software that give diffrent
behavior with CC 5.3 and CC 4.2. The C++ file that has the bug, the
'bug.cxx' is attached in-line down.

'bug.cxx' ---> The C++ file generated from the 'gperf' file.

Please note that the following command line has been used for
generating
the C++ file from 'gperf' file :
gperf -a -o -G -LANSI-C -k 1 -N _isContainerWord
alfContainerWords.gperf > bug.cxx

Now, if we look in to the value of 'asso_values[(unsigned
char)str[0]]'
(at line number '51' in the file 'bug.cxx'), it gives different in
different result with CC 5.3 and CC 4.2 respectively. For an instance,
let's consider the value of 'str[0]' as 'i', then the values shows by
CC
4.2 binary are as follow :
Value of 'str[0]' ---> 'i'
Value of '(unsigned char)str[0]' ---> 'i'
Value of 'asso_values[(unsigned char)str[0]]' ---> '\0'
And these values is expected. But the binary with CC 5.3 showing
something different. The values shows by CC 5.3 are as follow :
Value of 'str[0]' ---> 'i'
Value of '(unsigned char)str[0]' ---> 'i'
Value of 'asso_values[(unsigned char)str[0]]' ---> '\024'
The first two values are fine, but the last one is not at all
expected.

For the CC5.3 compiled program the asso_values array never gets
initialised and points to the corrupted memory location from the very
beginning. It doesnot get re-initialised when I call the hash
function.

Any idea why this is so?
Appreciate your response,

=============
bug.cxx file
=============
/* ANSI-C code produced by gperf version 2.7.2 */
/* Command-line: /system/pkg/gperf/2.7.2/bin/sparc-sun-solaris2.8/gperf
-a -o -G -LANSI-C -k 1 -N _isContainerWord alfContainerWords.gperf */
#include <string.h>

#define TOTAL_KEYWORDS 6
#define MIN_WORD_LENGTH 2
#define MAX_WORD_LENGTH 11
#define MIN_HASH_VALUE 2
#define MAX_HASH_VALUE 11
/* maximum key range = 10, duplicates = 0 */

#ifdef __GNUC__
__inline
#else
#ifdef __cplusplus
inline
#endif
#endif
static unsigned int
hash (register const char *str, register unsigned int len)
{
static unsigned char asso_values[] =
{
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 2, 12, 12, 0, 12, 12, 0, 12,
12, 12, 12, 12, 12, 0, 0, 12, 0, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12
};
return len + asso_values[(unsigned char)str[0]];
}

static const char * wordlist[] =
{
"", "",
"to",
"",
"scan",
"limit",
"from",
"", "",
"violation",
"",
"information"
};

#ifdef __GNUC__
__inline
#endif
const char *
_isContainerWord (register const char *str, register unsigned int len)
{
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
register int key = hash (str, len);

if (key <= MAX_HASH_VALUE && key >= 0)
{
register const char *s = wordlist[key];

if (*str == *s && !strcmp (str + 1, s + 1))
return s;
}
}
return 0;
}
/* Wrapper function for _isContainerWord which gperf will generate */
const char* alfIsContainerWord(const char* name, int len)
{
return _isContainerWord(name, len);
}

// The following main() function has been added by Ujjwal
int main()
{
const char * name = "ibc"; int len = 11;
const char *ch;
ch = alfIsContainerWord( name, len);
return 0;
}

================================================================================
-Pr
 
R

Ron Natalie

Pr said:
Hi -
I have a code that works very well on 4.2, but fails on 5.3.

The Solaris 4.2 compiler is so off the standard language to be unusable.
It really didn't become usable until The 5.0 release. Even that release
is ancient (we've had 6.2 for years now and I suspect Sun has moved on
there as well).

I use 'gperf' generated C++ files in my software that give diffrent
behavior with CC 5.3 and CC 4.2. The C++ file that has the bug, the
'bug.cxx' is attached in-line down.

By the way heaven help you if you feed this code the string "" instead of
"ibc". The code would pass an invalid pointer to strcmp. I assume
this defect is part oif gperf's attempt to be cute rather than something
you introduced.

gperf IS outside the scope of this group, as are specific problems with
the SUNWspro compilers.

Other than that I can't see any problems off the top of my head.
I'd be more interested in these prints:

printf("%d\n", (unsigned char) str[0]);
Should be something like 105.

And I'd print out a few values of the table (asso_values[ 105]).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top