I understand perfectly well. I was merely pointing two facts:


1. If malloc/realloc fails, it is not enough to ignore the fact that buffer == NULL. The indexing process has to be aborted in some way. Meaning, your added if statement should have an else clause, probably with an exception thrown. Or a CND instead to verify buffer != NULL.


2. Code redundancy in growBuffer and friends.


I'm interested in hearing Ben's opinion on what actions to take, or yours if you have any. I will tackle later when I'll have more time.


Itamar.


On 8/2/2011 7:19 PM, Rustem Alimov wrote:

Hi,

you don't understand... If buffer == NULL, then
_tcsncpy(buffer,_term->text(), bufferLength); - at this point we have potential bug

Need

[code]
        //Instantiate the new buffer + 1 is needed for terminator '\0'
        if ( buffer == NULL )
            buffer = (TCHAR*)malloc(sizeof(TCHAR) * (bufferLength+1));
        else
buffer = (TCHAR*)realloc(buffer, sizeof(TCHAR) * (bufferLength+1));

        if (buffer != NULL && (copy || force_copy) ){
            //Copy the text of term into buffer
            _tcsncpy(buffer,_term->text(), bufferLength);
        }
[/code]


2011/1/27 Itamar Syn-Hershko <ita...@code972.com <mailto:ita...@code972.com>>

    Hi,


    If malloc / realloc returns NULL the indexing process has to be
    aborted anyway, and the only way I can think of doing this is
    throwing an exception. Did you have other idea in mind?


    Also, I'm not sure why growBuffer is used there at all. This is a
    simple TCHAR array being used as a buffer, why can't we generalize
    this piece of code or use some STL alternatives?


    Looking in files_list.txt it seems to be Ben's code, so perhaps he
    can give us some answers...


    Itamar.


    On 22/10/2010 12:12 PM, Rustem Alimov wrote:

    Hi,

    src/core/CLucene/index/SegmentTermEnum.cpp : line 377

    [code]
            //Instantiate the new buffer + 1 is needed for terminator
    '\0'
            if ( buffer == NULL )
                buffer = (TCHAR*)malloc(sizeof(TCHAR) *
    (bufferLength+1));
            else
                buffer = (TCHAR*)realloc(buffer, sizeof(TCHAR) *
    (bufferLength+1));

            if ( copy || force_copy){
                //Copy the text of term into buffer
                _tcsncpy(buffer,_term->text(),bufferLength);
            }
    [/code]

    If malloc / realloc return NULL?


    
------------------------------------------------------------------------------
    Nokia and AT&T present the 2010 Calling All Innovators-North America contest
    Create new apps&  games for the Nokia N8 for consumers in  U.S. and Canada
    $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
    Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
    http://p.sf.net/sfu/nokia-dev2dev


    _______________________________________________
    CLucene-developers mailing list
    CLucene-developers@lists.sourceforge.net  
<mailto:CLucene-developers@lists.sourceforge.net>
    https://lists.sourceforge.net/lists/listinfo/clucene-developers

    
------------------------------------------------------------------------------
    Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
    Finally, a world-class log management solution at an even better
    price-free!
    Download using promo code Free_Logger_4_Dev2Dev. Offer expires
    February 28th, so secure your free ArcSight Logger TODAY!
    http://p.sf.net/sfu/arcsight-sfd2d
    _______________________________________________
    CLucene-developers mailing list
    CLucene-developers@lists.sourceforge.net
    <mailto:CLucene-developers@lists.sourceforge.net>
    https://lists.sourceforge.net/lists/listinfo/clucene-developers



------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb


_______________________________________________
CLucene-developers mailing list
CLucene-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/clucene-developers
------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
CLucene-developers mailing list
CLucene-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/clucene-developers

Reply via email to