Remove useless check from xkb_intern_atom The "makeit" variable is always true. Remove it and de-indent. (Also change the type of the "len" variable to size_t to avoid some useless casting). 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
diff --git a/src/atom.c b/src/atom.c
index f39ba45..f26e23a 100644
--- a/src/atom.c
+++ b/src/atom.c
@@ -89,9 +89,9 @@ typedef struct _Node {
#define BAD_RESOURCE 0xe0000000
static xkb_atom_t lastAtom = XKB_ATOM_NONE;
-static NodePtr atomRoot = NULL;
+static NodePtr atomRoot;
static unsigned long tableLength;
-static NodePtr *nodeTable = NULL;
+static NodePtr *nodeTable;
const char *
XkbcAtomText(xkb_atom_t atom)
@@ -116,11 +116,11 @@ xkb_atom_t
xkb_intern_atom(const char *string)
{
NodePtr *np;
+ NodePtr nd;
unsigned i;
int comp;
unsigned int fp = 0;
- unsigned len;
- int makeit = True;
+ size_t len;
if (!string)
return XKB_ATOM_NONE;
@@ -139,7 +139,7 @@ xkb_intern_atom(const char *string)
np = &((*np)->right);
else {
/* now start testing the strings */
- comp = strncmp(string, (*np)->string, (int)len);
+ comp = strncmp(string, (*np)->string, len);
if ((comp < 0) || ((comp == 0) && (len < strlen((*np)->string))))
np = &((*np)->left);
else if (comp > 0)
@@ -149,53 +149,47 @@ xkb_intern_atom(const char *string)
}
}
- if (makeit) {
- NodePtr nd;
+ nd = malloc(sizeof(NodeRec));
+ if (!nd)
+ return BAD_RESOURCE;
- nd = malloc(sizeof(NodeRec));
- if (!nd)
- return BAD_RESOURCE;
-
- nd->string = malloc(len + 1);
- if (!nd->string) {
+ nd->string = malloc(len + 1);
+ if (!nd->string) {
+ free(nd);
+ return BAD_RESOURCE;
+ }
+ strncpy(nd->string, string, len);
+ nd->string[len] = 0;
+
+ if ((lastAtom + 1) >= tableLength) {
+ NodePtr *table;
+ int newLength;
+
+ if (tableLength == 0)
+ newLength = InitialTableSize;
+ else
+ newLength = tableLength * 2;
+
+ table = realloc(nodeTable, newLength * sizeof(NodePtr));
+ if (!table) {
+ if (nd->string != string)
+ free(nd->string);
free(nd);
return BAD_RESOURCE;
}
- strncpy(nd->string, string, (int)len);
- nd->string[len] = 0;
-
- if ((lastAtom + 1) >= tableLength) {
- NodePtr *table;
- int newLength;
-
- if (tableLength == 0)
- newLength = InitialTableSize;
- else
- newLength = tableLength * 2;
-
- table = realloc(nodeTable, newLength * sizeof(NodePtr));
- if (!table) {
- if (nd->string != string)
- free(nd->string);
- free(nd);
- return BAD_RESOURCE;
- }
- tableLength = newLength;
- table[XKB_ATOM_NONE] = NULL;
+ tableLength = newLength;
+ table[XKB_ATOM_NONE] = NULL;
- nodeTable = table;
- }
+ nodeTable = table;
+ }
- *np = nd;
- nd->left = nd->right = NULL;
- nd->fingerPrint = fp;
- nd->a = (++lastAtom);
- *(nodeTable + lastAtom) = nd;
+ *np = nd;
+ nd->left = nd->right = NULL;
+ nd->fingerPrint = fp;
+ nd->a = (++lastAtom);
+ *(nodeTable + lastAtom) = nd;
- return nd->a;
- }
- else
- return XKB_ATOM_NONE;
+ return nd->a;
}
static void