Avoid calls to strlen() when checking for empty strings.

Change-Id: I3de322006623483cbf20218da071a9da5d7b2e2b
Signed-off-by: Anmol Sarma <me@anmolsarma.in>
pull/211/merge
Anmol Sarma 10 years ago committed by Roger Light
parent b4f7819c94
commit 13d869b8df

@ -150,7 +150,7 @@ int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, bool clean_se
mosq->last_retry_check = 0;
mosq->clean_session = clean_session;
if(id){
if(strlen(id) == 0){
if(STREMPTY(id)){
return MOSQ_ERR_INVAL;
}
mosq->id = _mosquitto_strdup(id);
@ -552,7 +552,7 @@ int mosquitto_publish(struct mosquitto *mosq, int *mid, const char *topic, int p
int queue_status;
if(!mosq || !topic || qos<0 || qos>2) return MOSQ_ERR_INVAL;
if(strlen(topic) == 0) return MOSQ_ERR_INVAL;
if(STREMPTY(topic)) return MOSQ_ERR_INVAL;
if(payloadlen < 0 || payloadlen > MQTT_MAX_PAYLOAD) return MOSQ_ERR_PAYLOAD_SIZE;
if(mosquitto_pub_topic_check(topic) != MOSQ_ERR_SUCCESS){

@ -257,4 +257,6 @@ struct mosquitto {
#endif
};
#define STREMPTY(str) (str[0] == '\0')
#endif

@ -640,7 +640,7 @@ int _config_read_file_core(struct mqtt3_config *config, bool reload, const char
if(!key){
_mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory.");
return MOSQ_ERR_NOMEM;
}else if(strlen(key) == 0){
}else if(STREMPTY(key)){
_mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Invalid auth_opt_ config option.");
return MOSQ_ERR_INVAL;
}

@ -102,7 +102,7 @@ int mqtt3_handle_publish(struct mosquitto_db *db, struct mosquitto *context)
retain = (header & 0x01);
if(_mosquitto_read_string(&context->in_packet, &topic)) return 1;
if(strlen(topic) == 0){
if(STREMPTY(topic)){
/* Invalid publish topic, disconnect client. */
_mosquitto_free(topic);
return 1;

@ -236,7 +236,7 @@ int mqtt3_handle_connect(struct mosquitto_db *db, struct mosquitto *context)
rc = 1;
goto handle_connect_error;
}
if(strlen(will_topic) == 0){
if(STREMPTY(will_topic)){
rc = 1;
goto handle_connect_error;
}

Loading…
Cancel
Save