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>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
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;
}
}
}