diff options
author | Adam Jackson <ajax@redhat.com> | 2009-05-08 14:15:21 -0400 |
---|---|---|
committer | Adam Jackson <ajax@redhat.com> | 2009-05-08 14:15:21 -0400 |
commit | d36a99d961c6649ca1b0319c2aadc6763edb07ad (patch) | |
tree | 5dd7b28ec56eab55806c209d327b03cb49cc54fd | |
parent | 29f27b16dbe511a27a0e953b32913f9d9bf24f2d (diff) | |
download | xorg-lib-libxkbfile-d36a99d961c6649ca1b0319c2aadc6763edb07ad.tar.gz |
Semi-revert 33b839e16fe681ba915658f824ceb1b252084ea4
_XkbDupString() checks for NULL, strdup doesn't. Still, implement in
terms of real strdup and skip the calloc.
-rw-r--r-- | src/XKBfileInt.h | 6 | ||||
-rw-r--r-- | src/maprules.c | 50 | ||||
-rw-r--r-- | src/xkbconfig.c | 6 | ||||
-rw-r--r-- | src/xkmread.c | 10 |
4 files changed, 39 insertions, 33 deletions
diff --git a/src/XKBfileInt.h b/src/XKBfileInt.h index 5573638..a99b7c8 100644 --- a/src/XKBfileInt.h +++ b/src/XKBfileInt.h @@ -65,6 +65,12 @@ _XFUNCPROTOBEGIN +static inline +char *_XkbDupString(const char *s) +{ + return s ? strdup(s) : NULL; +} + #define _XkbStrCaseEqual(s1,s2) (_XkbStrCaseCmp(s1,s2)==0) #ifdef NEED_STRCASECMP diff --git a/src/maprules.c b/src/maprules.c index b6d773c..104dad3 100644 --- a/src/maprules.c +++ b/src/maprules.c @@ -449,8 +449,8 @@ Bool append = False; } if (*words == '\0') return False; - group->name = strdup(gname); - group->words = strdup(words); + group->name = _XkbDupString(gname); + group->words = _XkbDupString(words); for (i = 1, words = group->words; *words; words++) { if ( *words == ' ') { *words++ = '\0'; @@ -501,17 +501,17 @@ Bool append = False; rule->flags|= XkbRF_Append; else rule->flags|= XkbRF_Normal; - rule->model= strdup(tmp.name[MODEL]); - rule->layout= strdup(tmp.name[LAYOUT]); - rule->variant= strdup(tmp.name[VARIANT]); - rule->option= strdup(tmp.name[OPTION]); - - rule->keycodes= strdup(tmp.name[KEYCODES]); - rule->symbols= strdup(tmp.name[SYMBOLS]); - rule->types= strdup(tmp.name[TYPES]); - rule->compat= strdup(tmp.name[COMPAT]); - rule->geometry= strdup(tmp.name[GEOMETRY]); - rule->keymap= strdup(tmp.name[KEYMAP]); + rule->model= _XkbDupString(tmp.name[MODEL]); + rule->layout= _XkbDupString(tmp.name[LAYOUT]); + rule->variant= _XkbDupString(tmp.name[VARIANT]); + rule->option= _XkbDupString(tmp.name[OPTION]); + + rule->keycodes= _XkbDupString(tmp.name[KEYCODES]); + rule->symbols= _XkbDupString(tmp.name[SYMBOLS]); + rule->types= _XkbDupString(tmp.name[TYPES]); + rule->compat= _XkbDupString(tmp.name[COMPAT]); + rule->geometry= _XkbDupString(tmp.name[GEOMETRY]); + rule->keymap= _XkbDupString(tmp.name[KEYMAP]); rule->layout_num = rule->variant_num = 0; for (i = 0; i < nread; i++) { @@ -556,7 +556,7 @@ MakeMultiDefs(XkbRF_MultiDefsPtr mdefs, XkbRF_VarDefsPtr defs) bzero((char *)mdefs,sizeof(XkbRF_MultiDefsRec)); mdefs->model = defs->model; - mdefs->options = strdup(defs->options); + mdefs->options = _XkbDupString(defs->options); if (mdefs->options) squeeze_spaces(mdefs->options); if (defs->layout) { @@ -565,7 +565,7 @@ MakeMultiDefs(XkbRF_MultiDefsPtr mdefs, XkbRF_VarDefsPtr defs) } else { char *p; int i; - mdefs->layout[1] = strdup(defs->layout); + mdefs->layout[1] = _XkbDupString(defs->layout); if (mdefs->layout[1] == NULL) return False; squeeze_spaces(mdefs->layout[1]); @@ -589,7 +589,7 @@ MakeMultiDefs(XkbRF_MultiDefsPtr mdefs, XkbRF_VarDefsPtr defs) } else { char *p; int i; - mdefs->variant[1] = strdup(defs->variant); + mdefs->variant[1] = _XkbDupString(defs->variant); if (mdefs->variant[1] == NULL) return False; squeeze_spaces(mdefs->variant[1]); @@ -625,7 +625,7 @@ Apply(char *src, char **dst) *dst= _Concat(*dst, src); } else { if (*dst == NULL) - *dst= strdup(src); + *dst= _XkbDupString(src); } } } @@ -1069,8 +1069,8 @@ XkbRF_AddVarDescCopy(XkbRF_DescribeVarsPtr vars,XkbRF_VarDescPtr from) XkbRF_VarDescPtr nd; if ((nd=XkbRF_AddVarDesc(vars))!=NULL) { - nd->name= strdup(from->name); - nd->desc= strdup(from->desc); + nd->name= _XkbDupString(from->name); + nd->desc= _XkbDupString(from->desc); } return nd; } @@ -1098,7 +1098,7 @@ XkbRF_AddVarToDescribe(XkbRF_RulesPtr rules,char *name) rules->extra= NULL; return NULL; } - rules->extra_names[rules->num_extra]= strdup(name); + rules->extra_names[rules->num_extra]= _XkbDupString(name); bzero(&rules->extra[rules->num_extra],sizeof(XkbRF_DescribeVarsRec)); return &rules->extra[rules->num_extra++]; } @@ -1389,30 +1389,30 @@ Status rtrn; out=(char*)data; end=out+nitems; if (out && (*out) && rf_rtrn) - *rf_rtrn= strdup(out); + *rf_rtrn= _XkbDupString(out); out+=strlen(out)+1; if (out<end) { if (*out) - vd_rtrn->model= strdup(out); + vd_rtrn->model= _XkbDupString(out); out+=strlen(out)+1; } if (out<end) { if (*out) - vd_rtrn->layout= strdup(out); + vd_rtrn->layout= _XkbDupString(out); out+=strlen(out)+1; } if (out<end) { if (*out) - vd_rtrn->variant= strdup(out); + vd_rtrn->variant= _XkbDupString(out); out+=strlen(out)+1; } if (out<end) { if (*out) - vd_rtrn->options= strdup(out); + vd_rtrn->options= _XkbDupString(out); out+=strlen(out)+1; } diff --git a/src/xkbconfig.c b/src/xkbconfig.c index dd04e81..37272ce 100644 --- a/src/xkbconfig.c +++ b/src/xkbconfig.c @@ -377,7 +377,7 @@ XkbCFAddModByName( XkbConfigRtrnPtr rtrn, last->merge= merge; last->name= NULL; } - last->name= strdup(name); + last->name= _XkbDupString(name); } return last; } @@ -501,7 +501,7 @@ unsigned what; } if (*str!=NULL) _XkbFree(*str); - *str= strdup(val.str); + *str= _XkbDupString(val.str); break; case _XkbCF_InitialMods: case _XkbCF_IgnoreLockMods: @@ -1060,7 +1060,7 @@ DefaultFinish( XkbConfigFieldsPtr fields, return DefaultCleanUp(rtrn); if (what==XkbCF_Check) { if ((rtrn->symbols==NULL)&&(rtrn->phys_symbols!=NULL)) - rtrn->symbols= strdup(rtrn->phys_symbols); + rtrn->symbols= _XkbDupString(rtrn->phys_symbols); } if ((what==XkbCF_Apply)||(what==XkbCF_Check)) { if (xkb && xkb->names && (rtrn->num_unbound_mods>0)) diff --git a/src/xkmread.c b/src/xkmread.c index b746ce8..bf46bec 100644 --- a/src/xkmread.c +++ b/src/xkmread.c @@ -779,9 +779,9 @@ int nRead=0; doodad->text.height= doodadWire.text.height; doodad->text.color_ndx= doodadWire.text.color_ndx; nRead+= XkmGetCountedString(file,buf,100); - doodad->text.text= strdup(buf); + doodad->text.text= _XkbDupString(buf); nRead+= XkmGetCountedString(file,buf,100); - doodad->text.font= strdup(buf); + doodad->text.font= _XkbDupString(buf); break; case XkbIndicatorDoodad: doodad->indicator.shape_ndx= doodadWire.indicator.shape_ndx; @@ -793,7 +793,7 @@ int nRead=0; doodad->logo.color_ndx= doodadWire.logo.color_ndx; doodad->logo.shape_ndx= doodadWire.logo.shape_ndx; nRead+= XkmGetCountedString(file,buf,100); - doodad->logo.logo_name= strdup(buf); + doodad->logo.logo_name= _XkbDupString(buf); break; default: /* report error? */ @@ -957,7 +957,7 @@ XkbGeometrySizesRec sizes; geom->width_mm= wireGeom.width_mm; geom->height_mm= wireGeom.height_mm; nRead+= XkmGetCountedString(file,buf,100); - geom->label_font= strdup(buf); + geom->label_font= _XkbDupString(buf); if (wireGeom.num_properties>0) { char val[1024]; for (i=0;i<wireGeom.num_properties;i++) { @@ -1213,7 +1213,7 @@ char name[100]; return NULL; } if (XkmGetCountedString(file,name,100)>0) - return strdup(name); + return _XkbDupString(name); break; default: _XkbLibError(_XkbErrBadImplementation, |