if (num > 0) {
if (num > 0 && strlen(value[0]) + 5 <= sizeof(cset_name)) {
static void read_charset_define(lcd,gen)XLCd lcd;XLCdGenericPart *gen;{    int i=0;    char csd[16],cset_name[256];    char name[BUFSIZ];    XlcCharSet charsetd;    char **value;    int num,new;    XlcSide side = XlcUnknown;    char *tmp;    for(i=0;;i++){ /* loop start */        charsetd = 0;        sprintf(csd, "csd%d", i);        /* charset_name   */        sprintf(name, "%s.%s", csd , "charset_name");        _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);        _XlcDbg_printValue(name,value,num);        if (num > 0) {            strcpy(cset_name,value[0]);            sprintf(name, "%s.%s", csd , "side");            _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);            if (num > 0) {                _XlcDbg_printValue(name,value,num);                if( !_XlcNCompareISOLatin1(value[0], "none", 4) ){                    side =  XlcNONE ;                    strcat(cset_name,":none");                } else                if( !_XlcNCompareISOLatin1(value[0], "GL", 2) ){                    side =  XlcGL ;                    strcat(cset_name,":GL");                } else {                    side =  XlcGR ;                    strcat(cset_name,":GR");                }                if (charsetd == NULL &&                    (charsetd = srch_charset_define(cset_name,&new)) == NULL)                    return ;            }        } else {            if(i == 0){                continue ;            } else {                break ;            }        }        if(new){            tmp = (char *)Xmalloc(strlen(cset_name)+1);            if(tmp == NULL){                return ;            }            strcpy(tmp,cset_name);            charsetd->name = tmp;        }        /* side   */        charsetd->side =  side ;        /* length */        sprintf(name, "%s.%s", csd , "length");        _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);        if (num > 0) {            _XlcDbg_printValue(name,value,num);            charsetd->char_size = atoi(value[0]);        }        /* gc_number */        sprintf(name, "%s.%s", csd , "gc_number");        _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);        if (num > 0) {            _XlcDbg_printValue(name,value,num);            charsetd->set_size = atoi(value[0]);        }        /* string_encoding */        sprintf(name, "%s.%s", csd , "string_encoding");        _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);        if (num > 0) {            _XlcDbg_printValue(name,value,num);            if(!strcmp("False",value[0])){                charsetd->string_encoding = False;            } else {                charsetd->string_encoding = True;            }        }        /* sequence */        sprintf(name, "%s.%s", csd , "sequence");        _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);        if (num > 0) {            _XlcDbg_printValue(name,value,num);/*            if(charsetd->ct_sequence){                Xfree(charsetd->ct_sequence);            }*/            tmp = (char *)Xmalloc(strlen(value[0])+1);            if(tmp == NULL){                return;            }            charsetd->ct_sequence = tmp;            string_to_encoding(value[0],tmp);        }        /* encoding_name */        sprintf(name, "%s.%s", csd , "encoding_name");        _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);        if (num > 0) {            _XlcDbg_printValue(name,value,num);/*            if(charsetd->encoding_name){                Xfree(charsetd->encoding_name);            }*/            tmp = (char *)Xmalloc(strlen(value[0]+1));            strcpy(tmp,value[0]);            charsetd->encoding_name = tmp;            charsetd->xrm_encoding_name =                XrmStringToQuark(tmp);        }    }}