Inconsistency noticed in apr_array_push function

Discussion in 'Apache' started by icode4fun, May 22, 2007.

  1. #1
    I am working on a project that involves writing an apache module in C.

    Project Objective: Write a code that captures query string values and sets cookie.

    The Problem
    The code worked fine when it was tested on server using SuSe 9.x version. All test cases gave desired results. However, when the code was moved to server using SuSe 10.x version, it started giving out-of-bound errors for arrays when the array size was 2, 4 and 8.

    This was noted based on the test cases performed. There could be other possibilities, which I am not aware of.

    The problem seems to be at the level of apr_array_push(). When the code was simultaneously tested on both servers, the problem was detected at this point.

    Code Excerpt:
    while (*cookieArrTmp &&
    (activityGroupStr = ap_getword_nc(r->pool, &cookieArrTmp, SEPARATOR_COMMA))){
    *(char **)apr_array_push(activityGroupArr) = apr_pstrdup(r->pool,activityGroupStr);
    }

    activityGroupCnt = activityGroupArr->nelts;
    char **groupArr = (char**)activityGroupArr->elts;


    Example of Error:
    If activityGroupCnt = 2 then groupArr[2] gives out-of-bound error , which is not the case if the activityGroupCnt = 3, 5, 6, 7, 9,10 and so on then.

    Similar error was found activityGroupCnt = 4 and 8.

    Would appreciate any suggestions to resolve this issue.
     
    icode4fun, May 22, 2007 IP