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
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