Skip to content

Commit c5b6026

Browse files
committed
Use memset() in constructors
Instead of setting each element individually to 0 or NULL, use memset. This also fixes the missing initialization of `conn->sm_disable`. Signed-off-by: Steffen Jaeckel <[email protected]>
1 parent 7fbf507 commit c5b6026

File tree

3 files changed

+5
-54
lines changed

3 files changed

+5
-54
lines changed

src/conn.c

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -142,28 +142,19 @@ xmpp_conn_t *xmpp_conn_new(xmpp_ctx_t *ctx)
142142

143143
conn = strophe_alloc(ctx, sizeof(xmpp_conn_t));
144144
if (conn != NULL) {
145+
memset(conn, 0, sizeof(xmpp_conn_t));
145146
conn->ctx = ctx;
146147

147148
conn->type = XMPP_UNKNOWN;
148149
conn->state = XMPP_STATE_DISCONNECTED;
149150

150-
conn->xsock = NULL;
151151
conn->sock = INVALID_SOCKET;
152152
conn->ka_timeout = KEEPALIVE_TIMEOUT;
153153
conn->ka_interval = KEEPALIVE_INTERVAL;
154154
conn->ka_count = KEEPALIVE_COUNT;
155-
conn->tls = NULL;
156-
conn->timeout_stamp = 0;
157-
conn->error = 0;
158-
conn->stream_error = NULL;
159155

160156
/* default send parameters */
161-
conn->blocking_send = 0;
162157
conn->send_queue_max = DEFAULT_SEND_QUEUE_MAX;
163-
conn->send_queue_len = 0;
164-
conn->send_queue_user_len = 0;
165-
conn->send_queue_head = NULL;
166-
conn->send_queue_tail = NULL;
167158

168159
/* default timeouts */
169160
conn->connect_timeout = CONNECT_TIMEOUT;
@@ -173,49 +164,14 @@ xmpp_conn_t *xmpp_conn_new(xmpp_ctx_t *ctx)
173164
strophe_free(conn->ctx, conn);
174165
return NULL;
175166
}
176-
conn->domain = NULL;
177-
conn->jid = NULL;
178-
conn->pass = NULL;
179-
conn->stream_id = NULL;
180-
conn->bound_jid = NULL;
181-
182-
conn->is_raw = 0;
183-
conn->tls_support = 0;
184-
conn->tls_disabled = 0;
185-
conn->tls_mandatory = 0;
186-
conn->tls_legacy_ssl = 0;
187-
conn->tls_trust = 0;
188-
conn->tls_failed = 0;
189-
conn->tls_cafile = NULL;
190-
conn->tls_capath = NULL;
191-
conn->tls_client_cert = NULL;
192-
conn->tls_client_key = NULL;
193-
conn->sasl_support = 0;
194-
conn->auth_legacy_enabled = 0;
195-
conn->secured = 0;
196-
conn->certfail_handler = NULL;
197-
conn->password_callback = NULL;
198-
conn->password_callback_userdata = NULL;
199167
tls_clear_password_cache(conn);
200168
conn->password_retries = 1;
201169

202-
conn->bind_required = 0;
203-
conn->session_required = 0;
204-
conn->sm_state = NULL;
205-
206170
conn->parser =
207171
parser_new(conn->ctx, _handle_stream_start, _handle_stream_end,
208172
_handle_stream_stanza, conn);
209-
conn->reset_parser = 0;
210-
211-
conn->stream_negotiation_completed = 0;
212-
conn->conn_handler = NULL;
213-
conn->userdata = NULL;
214-
conn->timed_handlers = NULL;
215173
/* we own (and will free) the hash values */
216174
conn->id_handlers = hash_new(conn->ctx, 32, NULL);
217-
conn->handlers = NULL;
218-
conn->sockopt_cb = NULL;
219175

220176
/* give the caller a reference to connection */
221177
conn->ref = 1;
@@ -1154,6 +1110,7 @@ long xmpp_conn_get_flags(const xmpp_conn_t *conn)
11541110
XMPP_CONN_FLAG_MANDATORY_TLS * conn->tls_mandatory |
11551111
XMPP_CONN_FLAG_LEGACY_SSL * conn->tls_legacy_ssl |
11561112
XMPP_CONN_FLAG_TRUST_TLS * conn->tls_trust |
1113+
XMPP_CONN_FLAG_DISABLE_SM * conn->sm_disable |
11571114
XMPP_CONN_FLAG_LEGACY_AUTH * conn->auth_legacy_enabled;
11581115

11591116
return flags;

src/ctx.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,8 @@ xmpp_ctx_t *xmpp_ctx_new(const xmpp_mem_t *mem, const xmpp_log_t *log)
465465
ctx = mem->alloc(sizeof(xmpp_ctx_t), mem->userdata);
466466

467467
if (ctx != NULL) {
468+
memset(ctx, 0, sizeof(xmpp_ctx_t));
469+
468470
if (mem != NULL)
469471
ctx->mem = mem;
470472
else
@@ -475,12 +477,9 @@ xmpp_ctx_t *xmpp_ctx_new(const xmpp_mem_t *mem, const xmpp_log_t *log)
475477
else
476478
ctx->log = log;
477479

478-
ctx->connlist = NULL;
479-
ctx->timed_handlers = NULL;
480480
ctx->loop_status = XMPP_LOOP_NOTSTARTED;
481481
ctx->rand = xmpp_rand_new(ctx);
482482
ctx->timeout = EVENT_LOOP_DEFAULT_TIMEOUT;
483-
ctx->verbosity = 0;
484483
if (ctx->rand == NULL) {
485484
strophe_free(ctx, ctx);
486485
ctx = NULL;

src/stanza.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,10 @@ xmpp_stanza_t *xmpp_stanza_new(xmpp_ctx_t *ctx)
4242

4343
stanza = strophe_alloc(ctx, sizeof(xmpp_stanza_t));
4444
if (stanza != NULL) {
45+
memset(stanza, 0, sizeof(xmpp_stanza_t));
4546
stanza->ref = 1;
4647
stanza->ctx = ctx;
4748
stanza->type = XMPP_STANZA_UNKNOWN;
48-
stanza->prev = NULL;
49-
stanza->next = NULL;
50-
stanza->children = NULL;
51-
stanza->parent = NULL;
52-
stanza->data = NULL;
53-
stanza->attributes = NULL;
5449
}
5550

5651
return stanza;

0 commit comments

Comments
 (0)