]> granicus.if.org Git - jq/commitdiff
jq_util_input_init: Zero memory using calloc
authorMattias Hansson <hansson.mattias@gmail.com>
Thu, 4 Apr 2019 09:42:49 +0000 (11:42 +0200)
committerNico Williams <nico@cryptonector.com>
Thu, 4 Apr 2019 17:37:21 +0000 (12:37 -0500)
Calloc will zero the allocated memory which makes one memset and a
number of explicit zero assignments redundant.

src/util.c

index c5bf5f221f2ffc7c811e055c75daa4a15c52855c..1f2aac114b9fe6cb3d4fc5a3adf9c649dadc5c7b 100644 (file)
@@ -208,20 +208,11 @@ jq_util_input_state *jq_util_input_init(jq_util_msg_cb err_cb, void *err_cb_data
     err_cb = fprinter;
     err_cb_data = stderr;
   }
-  jq_util_input_state *new_state = jv_mem_alloc(sizeof(*new_state));
-  memset(new_state, 0, sizeof(*new_state));
+  jq_util_input_state *new_state = jv_mem_calloc(1, sizeof(*new_state));
   new_state->err_cb = err_cb;
   new_state->err_cb_data = err_cb_data;
-  new_state->parser = NULL;
-  new_state->current_input = NULL;
-  new_state->files = NULL;
-  new_state->nfiles = 0;
-  new_state->curr_file = 0;
   new_state->slurped = jv_invalid();
-  new_state->buf[0] = 0;
-  new_state->buf_valid_len = 0;
   new_state->current_filename = jv_invalid();
-  new_state->current_line = 0;
 
   return new_state;
 }