OSSP CVS Repository

ossp - Check-in [1330]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 1330
Date: 2001-Nov-14 13:02:40 (local)
2001-Nov-14 12:02:40 (UTC)
User:rse
Branch:
Comment: Safe time by cleaning up var_expand() myself instead of first writing down the wishes and having Peter do it himself afterwards: - use tokenbuf_init() instead of doing it manually - perform additional argument sanity checks - some minor coding style adjustments
Tickets:
Inspections:
Files:
ossp-pkg/var/var.c      1.14 -> 1.15     17 inserted, 15 deleted
ossp-pkg/var/var.h      1.7 -> 1.8     1 inserted, 0 deleted

ossp-pkg/var/var.c 1.14 -> 1.15

--- var.c        2001/11/14 11:11:01     1.14
+++ var.c        2001/11/14 12:02:40     1.15
@@ -1557,34 +1557,36 @@
     var_rc_t rc;
     tokenbuf_t output;
 
-    /* Expand the class description for valid variable names. */
+    /* Argument sanity checks */
+    if (input_buf == NULL || input_len == 0 || 
+        result == NULL || result_len == NULL ||
+        lookup == NULL || lookup_context == NULL)
+        return VAR_ERR_INVALID_ARGUMENT;
 
+    /* Optionally use default configuration */
     if (config == NULL)
         config = &var_config_default;
-    rc = expand_character_class(config->namechars, nameclass);
-    if (rc != VAR_OK)
+
+    /* Expand the class description for valid variable names. */
+    if ((rc = expand_character_class(config->namechars, nameclass)) != VAR_OK)
         return rc;
 
     /* Make sure that the specials defined in the configuration do not
        appear in the character name class. */
-
-    if (nameclass[(int) config->varinit] ||
-        nameclass[(int) config->startdelim] ||
-        nameclass[(int) config->enddelim] ||
-        nameclass[(int) config->escape])
+    if (nameclass[(int)config->varinit] ||
+        nameclass[(int)config->startdelim] ||
+        nameclass[(int)config->enddelim] ||
+        nameclass[(int)config->escape])
         return VAR_ERR_INVALID_CONFIGURATION;
 
     /* Call the parser. */
-
-    output.begin = output.end = NULL;
-    output.buffer_size = 0;
-    rc = input(input_buf, input_buf + input_len, config, nameclass,
-               lookup, lookup_context, force_expand, &output);
-    if (rc != VAR_OK) {
+    tokenbuf_init(&output);
+    if ((rc = input(input_buf, input_buf + input_len, config, nameclass,
+                    lookup, lookup_context, force_expand, &output)) != VAR_OK) {
         tokenbuf_free(&output);
         return rc;
     }
-    *result = (char *) output.begin;
+    *result = (char *)output.begin;
     *result_len = output.end - output.begin;
 
     return VAR_OK;


ossp-pkg/var/var.h 1.7 -> 1.8

--- var.h        2001/11/14 11:11:01     1.7
+++ var.h        2001/11/14 12:02:40     1.8
@@ -36,6 +36,7 @@
 
 typedef enum {
     VAR_ERR_CALLBACK = -64,
+    VAR_ERR_INVALID_ARGUMENT = -35,
     VAR_ERR_SUBMATCH_OUT_OF_RANGE = -34,
     VAR_ERR_UNKNOWN_QUOTED_PAIR_IN_REPLACE = -33,
     VAR_ERR_EMPTY_PADDING_FILL_STRING = -32,

CVSTrac 2.0.1