Fix possible null dereferences

Fix all reported null dereferences from clang-analyzer.
There seems to be one false negative (in file indicators.c), but it is
fixed anyway.

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-02-24 16:03:44 +02:00
parent 9005624f94
commit cca1c05097
8 changed files with 26 additions and 21 deletions

View File

@ -170,6 +170,7 @@ XkbcComputeSectionBounds(struct xkb_geometry * geom, struct xkb_section * sectio
default: default:
tbounds.x1 = tbounds.x2 = doodad->any.left; tbounds.x1 = tbounds.x2 = doodad->any.left;
tbounds.y1 = tbounds.y2 = doodad->any.top; tbounds.y1 = tbounds.y2 = doodad->any.top;
rbounds = &tbounds;
break; break;
} }

View File

@ -133,10 +133,9 @@ XkbcComputeEffectiveMap(struct xkb_desc * xkb, struct xkb_key_type * type,
if (map_rtrn) { if (map_rtrn) {
bzero(map_rtrn, type->mods.mask + 1); bzero(map_rtrn, type->mods.mask + 1);
for (i = 0; i < type->map_count; i++) { if (entry && entry->active)
if (entry->active) for (i = 0; i < type->map_count; i++)
map_rtrn[type->map[i].mods.mask] = type->map[i].level; map_rtrn[type->map[i].mods.mask] = type->map[i].level;
}
} }
return True; return True;

View File

@ -261,7 +261,7 @@ ApplyAliases(struct xkb_desc * xkb, Bool toGeom, AliasInfo ** info_in)
if (toGeom) if (toGeom)
a = &xkb->geom->key_aliases[nOld]; a = &xkb->geom->key_aliases[nOld];
else else
a = &xkb->names->key_aliases[nOld]; a = xkb->names ? &xkb->names->key_aliases[nOld] : NULL;
for (info = *info_in; info != NULL; info = (AliasInfo *) info->def.next) for (info = *info_in; info != NULL; info = (AliasInfo *) info->def.next)
{ {
if (info->alias[0] != '\0') if (info->alias[0] != '\0')

View File

@ -2244,12 +2244,12 @@ HandleGeometryVar(VarDef * stmt, struct xkb_desc * xkb, GeometryInfo * info)
info->errorCount++; info->errorCount++;
ret = ReportNotArray("keyboard", field.str, "geometry"); ret = ReportNotArray("keyboard", field.str, "geometry");
} }
if (!ExprResolveFloat(stmt->value, &tmp)) else if (!ExprResolveFloat(stmt->value, &tmp))
{ {
info->errorCount++; info->errorCount++;
ret = ReportBadType("keyboard", field.str, "geometry", "number"); ret = ReportBadType("keyboard", field.str, "geometry", "number");
} }
if (tmp.ival < 1) else if (tmp.ival < 1)
{ {
WARN("Keyboard height must be positive\n"); WARN("Keyboard height must be positive\n");
ACTION("Ignoring illegal keyboard height %s\n", ACTION("Ignoring illegal keyboard height %s\n",
@ -2303,7 +2303,7 @@ HandleGeometryVar(VarDef * stmt, struct xkb_desc * xkb, GeometryInfo * info)
info->errorCount++; info->errorCount++;
ret = ReportNotArray("keyboard", field.str, "geometry"); ret = ReportNotArray("keyboard", field.str, "geometry");
} }
if (!ExprResolveString(stmt->value, &tmp)) else if (!ExprResolveString(stmt->value, &tmp))
{ {
info->errorCount++; info->errorCount++;
ret = ReportBadType("keyboard", field.str, "geometry", "string"); ret = ReportBadType("keyboard", field.str, "geometry", "string");
@ -2323,7 +2323,7 @@ HandleGeometryVar(VarDef * stmt, struct xkb_desc * xkb, GeometryInfo * info)
info->errorCount++; info->errorCount++;
ret = ReportNotArray("keyboard", field.str, "geometry"); ret = ReportNotArray("keyboard", field.str, "geometry");
} }
if (!ExprResolveString(stmt->value, &tmp)) else if (!ExprResolveString(stmt->value, &tmp))
{ {
info->errorCount++; info->errorCount++;
ret = ReportBadType("keyboard", field.str, "geometry", "string"); ret = ReportBadType("keyboard", field.str, "geometry", "string");
@ -2572,11 +2572,14 @@ HandleOverlayDef(OverlayDef * def,
keyDef = (OverlayKeyDef *) keyDef->common.next) keyDef = (OverlayKeyDef *) keyDef->common.next)
{ {
key = uTypedCalloc(1, OverlayKeyInfo); key = uTypedCalloc(1, OverlayKeyInfo);
if ((!key) && warningLevel > 0) if (!key)
{ {
WSGO("Couldn't allocate OverlayKeyInfo\n"); if (warningLevel > 0)
ACTION("Overlay %s for section %s will be incomplete\n", {
XkbcAtomText(ol.name), scText(si)); WSGO("Couldn't allocate OverlayKeyInfo\n");
ACTION("Overlay %s for section %s will be incomplete\n",
XkbcAtomText(ol.name), scText(si));
}
return False; return False;
} }
strncpy(key->over, keyDef->over, XkbKeyNameLength); strncpy(key->over, keyDef->over, XkbKeyNameLength);
@ -2649,9 +2652,10 @@ HandleComplexKey(KeyDef * def, KeyInfo * key, GeometryInfo * info)
break; break;
default: default:
ERROR("Cannot determine field for unnamed expression\n"); ERROR("Cannot determine field for unnamed expression\n");
ACTION("Ignoring key %d in row %d of section %s\n", if (row)
row->nKeys + 1, row->section->nRows + 1, ACTION("Ignoring key %d in row %d of section %s\n",
rowText(row)); row->nKeys + 1, row->section->nRows + 1,
rowText(row));
return False; return False;
} }
} }

View File

@ -577,11 +577,11 @@ BindIndicators(struct xkb_desc * xkb, Bool force, LEDInfo *unbound,
{ {
*unboundRtrn = unbound; *unboundRtrn = unbound;
} }
else if (unbound) else
{ {
for (led = unbound; led != NULL; led = next) for (led = unbound; led != NULL; led = next)
{ {
next = (LEDInfo *) led->defs.next; next = led ? (LEDInfo *) led->defs.next : NULL;
free(led); free(led);
} }
} }

View File

@ -307,7 +307,7 @@ AddIndicatorName(KeyNamesInfo * info, IndicatorNameInfo * new)
new = NextIndicatorName(info); new = NextIndicatorName(info);
if (!new) if (!new)
{ {
WSGO("Couldn't allocate name for indicator %d\n", new->ndx); WSGO("Couldn't allocate name for indicator %d\n", old->ndx);
ACTION("Ignored\n"); ACTION("Ignored\n");
return False; return False;
} }
@ -565,7 +565,7 @@ HandleIncludeKeycodes(IncludeStmt * stmt, struct xkb_desc * xkb, KeyNamesInfo *
included = *info; included = *info;
bzero(info, sizeof(KeyNamesInfo)); bzero(info, sizeof(KeyNamesInfo));
} }
else if (strcmp(stmt->file, "computed") == 0) else if (stmt->file && strcmp(stmt->file, "computed") == 0)
{ {
xkb->flags |= AutoKeyNames; xkb->flags |= AutoKeyNames;
info->explicitMin = 0; info->explicitMin = 0;

View File

@ -573,7 +573,7 @@ AddPreserve(struct xkb_desc * xkb,
if (!old) if (!old)
{ {
WSGO("Couldn't allocate preserve in %s\n", TypeTxt(type)); WSGO("Couldn't allocate preserve in %s\n", TypeTxt(type));
ACTION("Preserve[%s] lost\n", PreserveIndexTxt(xkb, old)); ACTION("Preserve[%s] lost\n", PreserveIndexTxt(xkb, new));
return False; return False;
} }
*old = *new; *old = *new;

View File

@ -452,7 +452,8 @@ MergeKeyGroups(SymbolsInfo * info,
XkbcActionTypeText(use->type), XkbcActionTypeText(use->type),
XkbcActionTypeText(ignore->type)); XkbcActionTypeText(ignore->type));
} }
resultActs[i] = *use; if (use)
resultActs[i] = *use;
} }
} }
} }