From cca1c050971bd7a742a68212f3da904b5954759b Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 24 Feb 2012 16:03:44 +0200 Subject: [PATCH] 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 --- src/geom.c | 1 + src/xkb.c | 5 ++--- src/xkbcomp/alias.c | 2 +- src/xkbcomp/geometry.c | 26 +++++++++++++++----------- src/xkbcomp/indicators.c | 4 ++-- src/xkbcomp/keycodes.c | 4 ++-- src/xkbcomp/keytypes.c | 2 +- src/xkbcomp/symbols.c | 3 ++- 8 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/geom.c b/src/geom.c index 87b1f78..33e639d 100644 --- a/src/geom.c +++ b/src/geom.c @@ -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; } diff --git a/src/xkb.c b/src/xkb.c index a8c9caa..0870b3b 100644 --- a/src/xkb.c +++ b/src/xkb.c @@ -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; diff --git a/src/xkbcomp/alias.c b/src/xkbcomp/alias.c index fa27102..32d2e1e 100644 --- a/src/xkbcomp/alias.c +++ b/src/xkbcomp/alias.c @@ -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') diff --git a/src/xkbcomp/geometry.c b/src/xkbcomp/geometry.c index ddb2765..c6e7ba1 100644 --- a/src/xkbcomp/geometry.c +++ b/src/xkbcomp/geometry.c @@ -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; } } diff --git a/src/xkbcomp/indicators.c b/src/xkbcomp/indicators.c index 09baaaf..aa0a5a4 100644 --- a/src/xkbcomp/indicators.c +++ b/src/xkbcomp/indicators.c @@ -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); } } diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c index 906aa5f..e8d19db 100644 --- a/src/xkbcomp/keycodes.c +++ b/src/xkbcomp/keycodes.c @@ -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; diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c index 71f6075..f00a521 100644 --- a/src/xkbcomp/keytypes.c +++ b/src/xkbcomp/keytypes.c @@ -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; diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c index d82ec2e..1b98602 100644 --- a/src/xkbcomp/symbols.c +++ b/src/xkbcomp/symbols.c @@ -452,7 +452,8 @@ MergeKeyGroups(SymbolsInfo * info, XkbcActionTypeText(use->type), XkbcActionTypeText(ignore->type)); } - resultActs[i] = *use; + if (use) + resultActs[i] = *use; } } } -- 2.7.4