Discrepancy in the solaris CC 5.3 and 4.2

Discussion in 'C++' started by Pr, Jan 8, 2004.

  1. Pr

    Pr Guest

    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
     
    Pr, Jan 8, 2004
    #1
    1. Advertisements

  2. Pr

    Ron Natalie Guest

    "Pr" <> wrote in message news:...
    > 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]).
     
    Ron Natalie, Jan 8, 2004
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anand P Paralkar

    Discrepancy in CLB Usage Report

    Anand P Paralkar, Jul 2, 2003, in forum: VHDL
    Replies:
    0
    Views:
    1,089
    Anand P Paralkar
    Jul 2, 2003
  2. Gopal
    Replies:
    4
    Views:
    416
    Dario
    Oct 30, 2003
  3. KiwiBrian
    Replies:
    8
    Views:
    382
    Bone Ur
    Oct 30, 2007
  4. Cesar
    Replies:
    7
    Views:
    1,224
    Mike Treseler
    Jun 30, 2010
  5. Yan Huang
    Replies:
    24
    Views:
    308
    Jorge
    Oct 10, 2009
Loading...

Share This Page