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:
tbounds.x1 = tbounds.x2 = doodad->any.left;
tbounds.y1 = tbounds.y2 = doodad->any.top;
rbounds = &tbounds;
break;
}

View File

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

View File

@ -261,7 +261,7 @@ ApplyAliases(struct xkb_desc * xkb, Bool toGeom, AliasInfo ** info_in)
if (toGeom)
a = &xkb->geom->key_aliases[nOld];
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)
{
if (info->alias[0] != '\0')

View File

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

View File

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

View File

@ -307,7 +307,7 @@ AddIndicatorName(KeyNamesInfo * info, IndicatorNameInfo * new)
new = NextIndicatorName(info);
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");
return False;
}
@ -565,7 +565,7 @@ HandleIncludeKeycodes(IncludeStmt * stmt, struct xkb_desc * xkb, KeyNamesInfo *
included = *info;
bzero(info, sizeof(KeyNamesInfo));
}
else if (strcmp(stmt->file, "computed") == 0)
else if (stmt->file && strcmp(stmt->file, "computed") == 0)
{
xkb->flags |= AutoKeyNames;
info->explicitMin = 0;

View File

@ -573,7 +573,7 @@ AddPreserve(struct xkb_desc * xkb,
if (!old)
{
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;
}
*old = *new;

View File

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