Ticket #4123 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

bug in gdal-1.8.0/ogr/ogrsf_frmts/mitab/mitab_utils.cpp

Reported by: iskander Owned by: warmerdam
Priority: normal Milestone: 1.8.1
Component: OGR_SF Version: 1.8.0
Severity: normal Keywords: MITAB MIF basename parsing
Cc: dmorissette

Description (last modified by warmerdam) (diff)

Dear

we are using GDAL 1.8.0 and we found a bug in this method when reading MIF file that has basename with '.' (e.g. shape.001.MIF)

file location gdal-1.8.0/ogr/ogrsf_frmts/mitab/mitab_utils.cpp

///code of the method

/**********************************************************************
 *                       TABGetBasename()
 *
 * Extract the basename part of a complete file path.
 *
 * Returns a newly allocated string without the leading path (dirs) and
 * the extenstion.  The returned string should be freed using CPLFree().
 **********************************************************************/
char *TABGetBasename(const char *pszFname) {
    const char *pszTmp = NULL;

    /*-----------------------------------------------------------------
     * Skip leading path or use whole name if no path dividers are
     * encountered.
     *----------------------------------------------------------------*/
    pszTmp = pszFname + strlen(pszFname) - 1;
    while ( pszTmp != pszFname 
            && *pszTmp != '/' && *pszTmp != '\\' ) 
        pszTmp--;

    if( pszTmp != pszFname )
        pszTmp++;

    /*-----------------------------------------------------------------
     * Now allocate our own copy and remove extension
     *----------------------------------------------------------------*/
    char *pszBasename = CPLStrdup(pszTmp);
    int i;
 
 //>>>> your old code
 //for(i=0; pszBasename[i] != '\0'; i++)  //>>>>
 
 //>>>> our modification 
    for(i=strlen(pszBasename)-1; i >= 0; i--)  //>>>>
    {
        if (pszBasename[i] == '.')
        {
            pszBasename[i] = '\0';
            break;
        }
    }

    return pszBasename;
}

we replaced " for(i=0; pszBasename[i] != '\0'; i++)" by this " for(i=strlen(pszBasename)-1; i >= 0; i--)" and it worked TABGetBasename() doesn't support basename with . It should look for the '.' in the basename starting from the basename end

Please rectify this minor bug

Best Regards Iskander Benhadj

Change History

Changed 2 years ago by warmerdam

  • cc dmorissette added
  • keywords MITAB added
  • status changed from new to assigned
  • description modified (diff)
  • priority changed from high to normal

I'll address this in GDAL and upstream in mitab. Daniel let me know if there is something that looks wrong about the fellows proposed solution.

Changed 2 years ago by dmorissette

Looks fine to me. Thanks for handling it.

Changed 2 years ago by warmerdam

  • status changed from assigned to closed
  • resolution set to fixed

Change applied upstream in MITAB and pulled down into trunk (r22548) and 1.8 (r22549).

Thanks!

Note: See TracTickets for help on using tickets.