Commit aac1b435 authored by Alan Coopersmith's avatar Alan Coopersmith Committed by Peter Hutterer

Replace _XkbDupString with Xstrdup

The two functions have identical semantics, including safely returning
NULL when NULL is passed in (which POSIX strdup does not guarantee).

Some callers could probably be adjusted to call libc strdup directly,
when we know the input is non-NULL.
Signed-off-by: 's avatarAlan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: 's avatarPeter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: 's avatarDaniel Stone <daniel@fooishbar.org>
parent a4a2e814
......@@ -846,10 +846,6 @@ extern _X_EXPORT XkbGeometryPtr XkbLookupNamedGeometry(
Bool * /* shouldFree */
);
extern _X_EXPORT char * _XkbDupString(
const char * /* str */
);
extern _X_EXPORT void XkbConvertCase(
KeySym /* sym */,
KeySym * /* lower */,
......
......@@ -391,8 +391,8 @@ Bool append = FALSE;
}
if (*words == '\0')
return FALSE;
group->name = _XkbDupString(gname);
group->words = _XkbDupString(words);
group->name = Xstrdup(gname);
group->words = Xstrdup(words);
for (i = 1, words = group->words; *words; words++) {
if ( *words == ' ') {
*words++ = '\0';
......@@ -443,16 +443,16 @@ Bool append = FALSE;
rule->flags|= XkbRF_Append;
else
rule->flags|= XkbRF_Normal;
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->model= Xstrdup(tmp.name[MODEL]);
rule->layout= Xstrdup(tmp.name[LAYOUT]);
rule->variant= Xstrdup(tmp.name[VARIANT]);
rule->option= Xstrdup(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->keycodes= Xstrdup(tmp.name[KEYCODES]);
rule->symbols= Xstrdup(tmp.name[SYMBOLS]);
rule->types= Xstrdup(tmp.name[TYPES]);
rule->compat= Xstrdup(tmp.name[COMPAT]);
rule->geometry= Xstrdup(tmp.name[GEOMETRY]);
rule->layout_num = rule->variant_num = 0;
for (i = 0; i < nread; i++) {
......@@ -497,7 +497,7 @@ MakeMultiDefs(XkbRF_MultiDefsPtr mdefs, XkbRF_VarDefsPtr defs)
memset((char *)mdefs, 0, sizeof(XkbRF_MultiDefsRec));
mdefs->model = defs->model;
mdefs->options = _XkbDupString(defs->options);
mdefs->options = Xstrdup(defs->options);
if (mdefs->options) squeeze_spaces(mdefs->options);
if (defs->layout) {
......@@ -506,7 +506,7 @@ MakeMultiDefs(XkbRF_MultiDefsPtr mdefs, XkbRF_VarDefsPtr defs)
} else {
char *p;
int i;
mdefs->layout[1] = _XkbDupString(defs->layout);
mdefs->layout[1] = Xstrdup(defs->layout);
if (mdefs->layout[1] == NULL)
return FALSE;
squeeze_spaces(mdefs->layout[1]);
......@@ -530,7 +530,7 @@ MakeMultiDefs(XkbRF_MultiDefsPtr mdefs, XkbRF_VarDefsPtr defs)
} else {
char *p;
int i;
mdefs->variant[1] = _XkbDupString(defs->variant);
mdefs->variant[1] = Xstrdup(defs->variant);
if (mdefs->variant[1] == NULL)
return FALSE;
squeeze_spaces(mdefs->variant[1]);
......@@ -566,7 +566,7 @@ Apply(char *src, char **dst)
*dst= _Concat(*dst, src);
} else {
if (*dst == NULL)
*dst= _XkbDupString(src);
*dst= Xstrdup(src);
}
}
}
......
......@@ -5619,17 +5619,17 @@ ProcXkbGetKbdByName(ClientPtr client)
else fwant= stuff->want|stuff->need;
if ((!names.compat)&&
(fwant&(XkbGBN_CompatMapMask|XkbGBN_IndicatorMapMask))) {
names.compat= _XkbDupString("%");
names.compat= Xstrdup("%");
}
if ((!names.types)&&(fwant&(XkbGBN_TypesMask))) {
names.types= _XkbDupString("%");
names.types= Xstrdup("%");
}
if ((!names.symbols)&&(fwant&XkbGBN_SymbolsMask)) {
names.symbols= _XkbDupString("%");
names.symbols= Xstrdup("%");
}
geom_changed= ((names.geometry!=NULL)&&(strcmp(names.geometry,"%")!=0));
if ((!names.geometry)&&(fwant&XkbGBN_GeometryMask)) {
names.geometry= _XkbDupString("%");
names.geometry= Xstrdup("%");
geom_changed= FALSE;
}
......
......@@ -221,15 +221,15 @@ static void
XkbSetRulesUsed(XkbRMLVOSet *rmlvo)
{
free(XkbRulesUsed);
XkbRulesUsed= (rmlvo->rules?_XkbDupString(rmlvo->rules):NULL);
XkbRulesUsed= (rmlvo->rules?Xstrdup(rmlvo->rules):NULL);
free(XkbModelUsed);
XkbModelUsed= (rmlvo->model?_XkbDupString(rmlvo->model):NULL);
XkbModelUsed= (rmlvo->model?Xstrdup(rmlvo->model):NULL);
free(XkbLayoutUsed);
XkbLayoutUsed= (rmlvo->layout?_XkbDupString(rmlvo->layout):NULL);
XkbLayoutUsed= (rmlvo->layout?Xstrdup(rmlvo->layout):NULL);
free(XkbVariantUsed);
XkbVariantUsed= (rmlvo->variant?_XkbDupString(rmlvo->variant):NULL);
XkbVariantUsed= (rmlvo->variant?Xstrdup(rmlvo->variant):NULL);
free(XkbOptionsUsed);
XkbOptionsUsed= (rmlvo->options?_XkbDupString(rmlvo->options):NULL);
XkbOptionsUsed= (rmlvo->options?Xstrdup(rmlvo->options):NULL);
if (XkbWantRulesProp)
QueueWorkProc(XkbWriteRulesProp,NULL,NULL);
return;
......@@ -240,23 +240,23 @@ XkbSetRulesDflts(XkbRMLVOSet *rmlvo)
{
if (rmlvo->rules) {
free(XkbRulesDflt);
XkbRulesDflt= _XkbDupString(rmlvo->rules);
XkbRulesDflt= Xstrdup(rmlvo->rules);
}
if (rmlvo->model) {
free(XkbModelDflt);
XkbModelDflt= _XkbDupString(rmlvo->model);
XkbModelDflt= Xstrdup(rmlvo->model);
}
if (rmlvo->layout) {
free(XkbLayoutDflt);
XkbLayoutDflt= _XkbDupString(rmlvo->layout);
XkbLayoutDflt= Xstrdup(rmlvo->layout);
}
if (rmlvo->variant) {
free(XkbVariantDflt);
XkbVariantDflt= _XkbDupString(rmlvo->variant);
XkbVariantDflt= Xstrdup(rmlvo->variant);
}
if (rmlvo->options) {
free(XkbOptionsDflt);
XkbOptionsDflt= _XkbDupString(rmlvo->options);
XkbOptionsDflt= Xstrdup(rmlvo->options);
}
return;
}
......
......@@ -241,7 +241,7 @@ unsigned wantNames,wantConfig,wantDflts;
if (wantNames&XkmTypesMask) {
if (old_names->types!=None) {
tmp= NameForAtom(old_names->types);
names->types= _XkbDupString(tmp);
names->types= Xstrdup(tmp);
}
else {
wantDflts|= XkmTypesMask;
......@@ -251,7 +251,7 @@ unsigned wantNames,wantConfig,wantDflts;
if (wantNames&XkmCompatMapMask) {
if (old_names->compat!=None) {
tmp= NameForAtom(old_names->compat);
names->compat= _XkbDupString(tmp);
names->compat= Xstrdup(tmp);
}
else wantDflts|= XkmCompatMapMask;
complete|= XkmCompatMapMask;
......@@ -260,13 +260,13 @@ unsigned wantNames,wantConfig,wantDflts;
if (old_names->symbols==None)
return FALSE;
tmp= NameForAtom(old_names->symbols);
names->symbols= _XkbDupString(tmp);
names->symbols= Xstrdup(tmp);
complete|= XkmSymbolsMask;
}
if (wantNames&XkmKeyNamesMask) {
if (old_names->keycodes!=None) {
tmp= NameForAtom(old_names->keycodes);
names->keycodes= _XkbDupString(tmp);
names->keycodes= Xstrdup(tmp);
}
else wantDflts|= XkmKeyNamesMask;
complete|= XkmKeyNamesMask;
......@@ -275,7 +275,7 @@ unsigned wantNames,wantConfig,wantDflts;
if (old_names->geometry==None)
return FALSE;
tmp= NameForAtom(old_names->geometry);
names->geometry= _XkbDupString(tmp);
names->geometry= Xstrdup(tmp);
complete|= XkmGeometryMask;
wantNames&= ~XkmGeometryMask;
}
......
......@@ -51,19 +51,6 @@ XkbInternAtom(char *str,Bool only_if_exists)
return MakeAtom(str,strlen(str),!only_if_exists);
}
char *
_XkbDupString(const char *str)
{
char *new;
if (str==NULL)
return NULL;
new= calloc(strlen(str)+1,sizeof(char));
if (new)
strcpy(new,str);
return new;
}
/***====================================================================***/
static void *
......@@ -845,9 +832,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= _XkbDupString(buf);
doodad->text.text= Xstrdup(buf);
nRead+= XkmGetCountedString(file,buf,100);
doodad->text.font= _XkbDupString(buf);
doodad->text.font= Xstrdup(buf);
break;
case XkbIndicatorDoodad:
doodad->indicator.shape_ndx= doodadWire.indicator.shape_ndx;
......@@ -859,7 +846,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= _XkbDupString(buf);
doodad->logo.logo_name= Xstrdup(buf);
break;
default:
/* report error? */
......@@ -1021,7 +1008,7 @@ XkbGeometrySizesRec sizes;
geom->width_mm= wireGeom.width_mm;
geom->height_mm= wireGeom.height_mm;
nRead+= XkmGetCountedString(file,buf,100);
geom->label_font= _XkbDupString(buf);
geom->label_font= Xstrdup(buf);
if (wireGeom.num_properties>0) {
char val[1024];
for (i=0;i<wireGeom.num_properties;i++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment