You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by "Allen Wittenauer (JIRA)" <ji...@apache.org> on 2009/09/17 00:37:57 UTC

[jira] Created: (HADOOP-6263) SerialUtils.cc: dynamic allocation of arrays based on runtime variable is not portable

SerialUtils.cc: dynamic allocation of arrays based on runtime variable is not portable
--------------------------------------------------------------------------------------

                 Key: HADOOP-6263
                 URL: https://issues.apache.org/jira/browse/HADOOP-6263
             Project: Hadoop Common
          Issue Type: Bug
            Reporter: Allen Wittenauer


In SerialUtils.cc, the following code appears:

    int len;
    if (b < -120) {
      negative = true;
      len = -120 - b;
    } else {
      negative = false;
      len = -112 - b;
    }
    uint8_t barr[len];


as far as I'm aware, this is not legal in ANSI C and will be rejected by ANSI compliant compilers.  Instead, this should be malloc()'d based upon the size of len and free()'d later.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HADOOP-6263) SerialUtils.cc: dynamic allocation of arrays based on runtime variable is not portable

Posted by "Allen Wittenauer (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HADOOP-6263?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12756279#action_12756279 ] 

Allen Wittenauer commented on HADOOP-6263:
------------------------------------------

heh. I went with:

uint8_t *barr=(uint8_t * ) alloca(sizeof(uint8_t)*(len));

as my local fix, which SunStudio seems to accept as valid at least. 

> SerialUtils.cc: dynamic allocation of arrays based on runtime variable is not portable
> --------------------------------------------------------------------------------------
>
>                 Key: HADOOP-6263
>                 URL: https://issues.apache.org/jira/browse/HADOOP-6263
>             Project: Hadoop Common
>          Issue Type: Bug
>            Reporter: Allen Wittenauer
>
> In SerialUtils.cc, the following code appears:
>     int len;
>     if (b < -120) {
>       negative = true;
>       len = -120 - b;
>     } else {
>       negative = false;
>       len = -112 - b;
>     }
>     uint8_t barr[len];
> as far as I'm aware, this is not legal in ANSI C and will be rejected by ANSI compliant compilers.  Instead, this should be malloc()'d based upon the size of len and free()'d later.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HADOOP-6263) SerialUtils.cc: dynamic allocation of arrays based on runtime variable is not portable

Posted by "Brian Bockelman (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HADOOP-6263?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12756277#action_12756277 ] 

Brian Bockelman commented on HADOOP-6263:
-----------------------------------------

This is legal in C99, not C89.  Depends on which one you call ANSI C (I think it usually refers to C89) ;)

I believe it's better programming practice to allocate on the heap with malloc/free; I'm not sure if you gain any speed advantages either way.

> SerialUtils.cc: dynamic allocation of arrays based on runtime variable is not portable
> --------------------------------------------------------------------------------------
>
>                 Key: HADOOP-6263
>                 URL: https://issues.apache.org/jira/browse/HADOOP-6263
>             Project: Hadoop Common
>          Issue Type: Bug
>            Reporter: Allen Wittenauer
>
> In SerialUtils.cc, the following code appears:
>     int len;
>     if (b < -120) {
>       negative = true;
>       len = -120 - b;
>     } else {
>       negative = false;
>       len = -112 - b;
>     }
>     uint8_t barr[len];
> as far as I'm aware, this is not legal in ANSI C and will be rejected by ANSI compliant compilers.  Instead, this should be malloc()'d based upon the size of len and free()'d later.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.