aboutsummaryrefslogtreecommitdiffstats
path: root/src/mds-kbdc
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-12-07 18:10:02 +0100
committerMattias Andrée <maandree@operamail.com>2014-12-07 18:10:02 +0100
commit1db9f9c341ea538b5111197a0a101b9f5f368532 (patch)
treea3ca2ec3f05c58514c363a0134d14ba26f41389a /src/mds-kbdc
parentm (diff)
downloadmds-1db9f9c341ea538b5111197a0a101b9f5f368532.tar.gz
mds-1db9f9c341ea538b5111197a0a101b9f5f368532.tar.bz2
mds-1db9f9c341ea538b5111197a0a101b9f5f368532.tar.xz
mds-kbdc: compile-layout: bug fixes
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/mds-kbdc')
-rw-r--r--src/mds-kbdc/compile-layout.c15
-rw-r--r--src/mds-kbdc/string.c9
-rw-r--r--src/mds-kbdc/string.h2
3 files changed, 12 insertions, 14 deletions
diff --git a/src/mds-kbdc/compile-layout.c b/src/mds-kbdc/compile-layout.c
index c1cafd5..3a44f53 100644
--- a/src/mds-kbdc/compile-layout.c
+++ b/src/mds-kbdc/compile-layout.c
@@ -182,8 +182,7 @@ static int let(size_t variable, const char32_t* restrict string, const mds_kbdc_
if (value == NULL)
{
fail_if (tree = mds_kbdc_tree_create(C(COMPILED_STRING)), tree == NULL);
- tree->compiled_string.string = string_dup(string);
- fail_if (tree->compiled_string.string == NULL);
+ fail_if ((tree->compiled_string.string = string_dup(string)) == NULL);
}
/* Assign variable. */
@@ -691,12 +690,12 @@ static char32_t* parse_escape(mds_kbdc_tree_t* restrict tree, const char* restri
RETURN_ERROR(tree, ERROR, "variable ‘%.*s’ is an array", VARIABLE);
if (value->type != C(COMPILED_STRING))
NEW_ERROR(tree, INTERNAL_ERROR, "variable ‘%.*s’ is of impossible type", VARIABLE);
- fail_if (rc = string_dup(tree->compiled_string.string), rc == NULL);
+ fail_if (rc = string_dup(value->compiled_string.string), rc == NULL);
}
else
{
/* Octal or hexadecimal representation. */
- fail_if ( rc = malloc(2 * sizeof(char32_t)), rc == NULL);
+ fail_if (xmalloc(rc, 2, char32_t));
rc[0] = (char32_t)numbuf, rc[1] = -1;
}
@@ -1564,14 +1563,14 @@ static int compile_have_range(mds_kbdc_tree_assumption_have_range_t* restrict tr
/* Check that the primary bound is single-character. */
- if ((first[0] < 0) || (first[1] >= 0))
+ if ((first[0] == -1) || (first[1] != -1))
{
NEW_ERROR(tree, ERROR, "iteration boundary must be a single character string");
error->start = lineoff_first, lineoff_first = 0;
error->end = error->start + strlen(tree->first);
}
/* Check that the secondary bound is single-character. */
- if ((last[0] < 0) || (last[1] >= 0))
+ if ((last[0] == -1) || (last[1] != -1))
{
NEW_ERROR(tree, ERROR, "iteration boundary must be a single character string");
error->start = lineoff_last, lineoff_last = 0;
@@ -2001,14 +2000,14 @@ static int compile_for(mds_kbdc_tree_for_t* restrict tree)
/* Check that the primary bound is single-character. */
- if ((first[0] < 0) || (first[1] >= 0))
+ if ((first[0] == -1) || (first[1] != -1))
{
NEW_ERROR(tree, ERROR, "iteration boundary must be a single character string");
error->start = lineoff_first, lineoff_first = 0;
error->end = error->start + strlen(tree->first);
}
/* Check that the secondary bound is single-character. */
- if ((last[0] < 0) || (last[1] >= 0))
+ if ((last[0] == -1) || (last[1] != -1))
{
NEW_ERROR(tree, ERROR, "iteration boundary must be a single character string");
error->start = lineoff_last, lineoff_last = 0;
diff --git a/src/mds-kbdc/string.c b/src/mds-kbdc/string.c
index d6befe3..062aed3 100644
--- a/src/mds-kbdc/string.c
+++ b/src/mds-kbdc/string.c
@@ -33,7 +33,7 @@
size_t string_length(const char32_t* restrict string)
{
size_t i = 0;
- while (string[i] > -1)
+ while (string[i] != -1)
i++;
return i;
}
@@ -120,7 +120,7 @@ char* string_encode(const char32_t* restrict string)
* (actually we ca now fit 36 bits.)
* However, we only needed this in `string_decode` which would
* not require any changed, but we added it here for symmetry. */
- else rc[j++] = (char)((c >> 30) | 0xFE), _c(30), _c(24), _c(18), _c(12), _c(6), _c(0);
+ else rc[j++] = (char)0xFE, _c(30), _c(24), _c(18), _c(12), _c(6), _c(0);
#undef _t
#undef _c
}
@@ -134,7 +134,7 @@ char* string_encode(const char32_t* restrict string)
* Create duplicate of a string
*
* @param string The string
- * @return A duplicate of the strnig, `NULL` on error or if `string` is `NULL`
+ * @return A duplicate of the string, `NULL` on error or if `string` is `NULL`
*/
char32_t* string_dup(const char32_t* restrict string)
{
@@ -143,8 +143,7 @@ char32_t* string_dup(const char32_t* restrict string)
if (string == NULL)
return NULL;
n = string_length(string) + 1;
- rc = malloc(n * sizeof(char32_t));
- if (rc == NULL)
+ if (xmalloc(rc, n, char32_t))
return NULL;
memcpy(rc, string, n * sizeof(char32_t));
return rc;
diff --git a/src/mds-kbdc/string.h b/src/mds-kbdc/string.h
index 905c6a3..a07500d 100644
--- a/src/mds-kbdc/string.h
+++ b/src/mds-kbdc/string.h
@@ -57,7 +57,7 @@ char* string_encode(const char32_t* restrict string) __attribute__((nonnull));
* Create duplicate of a string
*
* @param string The string
- * @return A duplicate of the strnig, `NULL` on error or if `string` is `NULL`
+ * @return A duplicate of the string, `NULL` on error or if `string` is `NULL`
*/
char32_t* string_dup(const char32_t* restrict string);