]> andersk Git - libyaml.git/blobdiff - src/api.c
Do not update the raw buffer when not necessary (fixes #123).
[libyaml.git] / src / api.c
index a1fdf6bff5f6888f05f6ccc62f439a4281a8191a..0c4732e1520d227dfb537429c6b3e815b42865e3 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -74,7 +74,7 @@ YAML_DECLARE(int)
 yaml_string_extend(yaml_char_t **start,
         yaml_char_t **pointer, yaml_char_t **end)
 {
-    void *new_start = yaml_realloc(*start, (*end - *start)*2);
+    yaml_char_t *new_start = yaml_realloc(*start, (*end - *start)*2);
 
     if (!new_start) return 0;
 
@@ -117,12 +117,12 @@ yaml_string_join(
 YAML_DECLARE(int)
 yaml_stack_extend(void **start, void **top, void **end)
 {
-    void *new_start = yaml_realloc(*start, (*end - *start)*2);
+    void *new_start = yaml_realloc(*start, ((char *)*end - (char *)*start)*2);
 
     if (!new_start) return 0;
 
-    *top = new_start + (*top - *start);
-    *end = new_start + (*end - *start)*2;
+    *top = (char *)new_start + ((char *)*top - (char *)*start);
+    *end = (char *)new_start + ((char *)*end - (char *)*start)*2;
     *start = new_start;
 
     return 1;
@@ -138,13 +138,14 @@ yaml_queue_extend(void **start, void **head, void **tail, void **end)
     /* Check if we need to resize the queue. */
 
     if (*start == *head && *tail == *end) {
-        void *new_start = yaml_realloc(*start, (*end - *start)*2);
+        void *new_start = yaml_realloc(*start,
+                ((char *)*end - (char *)*start)*2);
 
         if (!new_start) return 0;
 
-        *head = new_start + (*head - *start);
-        *tail = new_start + (*tail - *start);
-        *end = new_start + (*end - *start)*2;
+        *head = (char *)new_start + ((char *)*head - (char *)*start);
+        *tail = (char *)new_start + ((char *)*tail - (char *)*start);
+        *end = (char *)new_start + ((char *)*end - (char *)*start)*2;
         *start = new_start;
     }
 
@@ -152,9 +153,9 @@ yaml_queue_extend(void **start, void **head, void **tail, void **end)
 
     if (*tail == *end) {
         if (*head != *tail) {
-            memmove(*start, *head, *tail - *head);
+            memmove(*start, *head, (char *)*tail - (char *)*head);
         }
-        *tail -= *head - *start;
+        *tail = (char *)*tail - (char *)*head + (char *)*start;
         *head = *start;
     }
 
@@ -249,7 +250,8 @@ yaml_string_read_handler(void *data, unsigned char *buffer, size_t size,
         return 1;
     }
 
-    if (size > (parser->input.string.end - parser->input.string.current)) {
+    if (size > (size_t)(parser->input.string.end
+                - parser->input.string.current)) {
         size = parser->input.string.end - parser->input.string.current;
     }
 
@@ -624,7 +626,7 @@ yaml_check_utf8(yaml_char_t *start, size_t length)
         unsigned char octet;
         unsigned int width;
         unsigned int value;
-        int k;
+        size_t k;
 
         octet = pointer[0];
         width = (octet & 0x80) == 0x00 ? 1 :
@@ -1119,6 +1121,8 @@ yaml_document_delete(yaml_document_t *document)
     } context;
     yaml_tag_directive_t *tag_directive;
 
+    context.error = YAML_NO_ERROR;  /* Eliminate a compliler warning. */
+
     assert(document);   /* Non-NULL document object is expected. */
 
     while (!STACK_EMPTY(&context, document->nodes)) {
@@ -1157,12 +1161,12 @@ yaml_document_delete(yaml_document_t *document)
  */
 
 YAML_DECLARE(yaml_node_t *)
-yaml_document_get_node(yaml_document_t *document, int node)
+yaml_document_get_node(yaml_document_t *document, int index)
 {
     assert(document);   /* Non-NULL document object is expected. */
 
-    if (node > 0 && document->nodes.start + node <= document->nodes.top) {
-        return document->nodes.start + node - 1;
+    if (index > 0 && document->nodes.start + index <= document->nodes.top) {
+        return document->nodes.start + index - 1;
     }
     return NULL;
 }
@@ -1203,7 +1207,7 @@ yaml_document_add_scalar(yaml_document_t *document,
     assert(value);      /* Non-NULL value is expected. */
 
     if (!tag) {
-        tag = YAML_DEFAULT_SCALAR_TAG;
+        tag = (yaml_char_t *)YAML_DEFAULT_SCALAR_TAG;
     }
 
     if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error;
@@ -1255,7 +1259,7 @@ yaml_document_add_sequence(yaml_document_t *document,
     assert(document);   /* Non-NULL document object is expected. */
 
     if (!tag) {
-        tag = YAML_DEFAULT_SEQUENCE_TAG;
+        tag = (yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG;
     }
 
     if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error;
@@ -1300,7 +1304,7 @@ yaml_document_add_mapping(yaml_document_t *document,
     assert(document);   /* Non-NULL document object is expected. */
 
     if (!tag) {
-        tag = YAML_DEFAULT_MAPPING_TAG;
+        tag = (yaml_char_t *)YAML_DEFAULT_MAPPING_TAG;
     }
 
     if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error;
@@ -1361,7 +1365,8 @@ yaml_document_append_mapping_pair(yaml_document_t *document,
     struct {
         yaml_error_type_t error;
     } context;
-    yaml_node_pair_t pair = { key, value };
+
+    yaml_node_pair_t pair;
 
     assert(document);       /* Non-NULL document is required. */
     assert(mapping > 0
@@ -1374,6 +1379,9 @@ yaml_document_append_mapping_pair(yaml_document_t *document,
     assert(value > 0 && document->nodes.start + value <= document->nodes.top);
                             /* Valid value id is required. */
 
+    pair.key = key;
+    pair.value = value;
+
     if (!PUSH(&context,
                 document->nodes.start[mapping-1].data.mapping.pairs, pair))
         return 0;
@@ -1381,3 +1389,4 @@ yaml_document_append_mapping_pair(yaml_document_t *document,
     return 1;
 }
 
+
This page took 0.173482 seconds and 4 git commands to generate.