Changeset 0950551c3ff5af5e8476f5dfec8f5da9c2695c93

Show
Ignore:
Timestamp:
01/30/06 23:02:47 (3 years ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1138658567 +0000
git-parent:

[9a1afdac05291bf7adb8986c0c66fa45533e2654]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1138658567 +0000
Message:

Fix error handling in (From|To)Locale

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/libvlc.c

    rd3cb142 r0950551  
    22 * libvlc.c: main libvlc source 
    33 ***************************************************************************** 
    4  * Copyright (C) 1998-2004 the VideoLAN team 
     4 * Copyright (C) 1998-2006 the VideoLAN team 
    55 * $Id$ 
    66 * 
     
    99 *          Gildas Bazin <gbazin@videolan.org> 
    1010 *          Derk-Jan Hartman <hartman at videolan dot org> 
     11 *          Rémi Denis-Courmont <rem # videolan : org> 
    1112 * 
    1213 * This program is free software; you can redistribute it and/or modify 
     
    4243#include <string.h>                                            /* strerror() */ 
    4344#include <stdlib.h>                                                /* free() */ 
     45#include <assert.h> 
    4446 
    4547#ifndef WIN32 
     
    27092711         */ 
    27102712        inb = strlen( locale ); 
    2711         outb = inb * 6 + 1; 
    2712  
    27132713        /* FIXME: I'm not sure about the value for the multiplication 
    27142714         * (for western people, multiplication by 3 (Latin9) is sufficient) */ 
     2715        outb = inb * 6 + 1; 
     2716 
    27152717        optr = output = calloc( outb , 1); 
    27162718 
     
    27212723                                                               == (size_t)-1 ) 
    27222724        { 
    2723             *optr = '?'; 
    2724             optr++
     2725            *optr++ = '?'; 
     2726            outb--
    27252727            iptr++; 
     2728            inb--; 
    27262729            vlc_iconv( libvlc.from_locale, NULL, NULL, NULL, NULL ); 
    27272730        } 
    27282731        vlc_mutex_unlock( &libvlc.from_locale_lock ); 
    27292732 
    2730         return realloc( output, strlen( output ) + 1 ); 
     2733        assert (inb == 0); 
     2734        assert (*iptr == '\0'); 
     2735        assert (*optr == '\0'); 
     2736        assert (strlen( output ) == (size_t)(optr - output)); 
     2737        return realloc( output, optr - output + 1 ); 
    27312738    } 
    27322739    return (char *)locale; 
     
    27622769                                                               == (size_t)-1 ) 
    27632770        { 
    2764             *optr = '?'; /* should not happen, and yes, it sucks */ 
    2765             optr++
     2771            *optr++ = '?'; /* should not happen, and yes, it sucks */ 
     2772            outb--
    27662773            iptr++; 
     2774            inb--; 
    27672775            vlc_iconv( libvlc.to_locale, NULL, NULL, NULL, NULL ); 
    27682776        } 
    27692777        vlc_mutex_unlock( &libvlc.to_locale_lock ); 
    27702778 
    2771         return realloc( output, strlen( output ) + 1 ); 
     2779        assert (inb == 0); 
     2780        assert (*iptr == '\0'); 
     2781        assert (*optr == '\0'); 
     2782        assert (strlen( output ) == (size_t)(optr - output)); 
     2783        return realloc( output, optr - output + 1 ); 
    27722784    } 
    27732785    return (char *)utf8;