* our own implementation instead. */
const LineInfo *lf = el_line(el);
const char *c = lf->buffer;
- if (global_profile->batch_mode) return;
+ if (global_profile->batch_mode) {
+ esl_mutex_unlock(MUTEX);
+ return;
+ }
printf("%s",prompt_str);
while (c < lf->lastchar && *c) {
putchar(*c);
r = -1; goto end;
} else if (!strncasecmp(cmd, "logfilter", 9)) {
cmd += 9;
- while (*cmd && *cmd == ' ') {
+ while (cmd && *cmd && *cmd == ' ') {
cmd++;
}
if (!esl_strlen_zero(cmd)) {
output_printf("Logfilter %s\n", logfilter ? "enabled" : "disabled");
} else if (!strncasecmp(cmd, "uuid", 4)) {
cmd += 4;
- while (*cmd && *cmd == ' ') {
+ while (cmd && *cmd && *cmd == ' ') {
cmd++;
}
if (!esl_strlen_zero(cmd)) {
if (handle->last_sr_event) {
if (handle->last_sr_event->body) {
output_printf("%s\n", handle->last_sr_event->body);
- } else if ((err = esl_event_get_header(handle->last_sr_event, "reply-text")) && !strncasecmp(err, "-err", 3)) {
+ } else if ((err = esl_event_get_header(handle->last_sr_event, "reply-text")) && !strncasecmp(err, "-err", 4)) {
output_printf("Error: %s!\n", err + 4);
}
}
static char* _strndup(const char *s, int n)
{
- char *r = (char*)malloc(n + 1), *d=r;
+ char *r = (char*)malloc(n + 1), *d;
+
+ assert(r);
+ d = r;
while (n > 0 && *s) {
*d = *s;
d++; s++; n--;
char cmd_str[2048] = "";
unsigned char ret = CC_REDISPLAY;
char *dup = _strndup(buffer, (int)(lastchar - buffer));
- char *buf = dup;
+ char *buf;
int sc = 0, offset = (int)(cursor - buffer), pos = (offset > 0) ? offset : 0;
char *p;
+
+ assert(dup);
+ buf = dup;
+
if (pos > 0) {
*(buf + pos) = '\0';
}
if (global_handle->last_sr_event && global_handle->last_sr_event->body) {
char *r = global_handle->last_sr_event->body;
char *w, *p1;
- if (r) {
- if ((w = strstr(r, "\n\nwrite="))) {
- int len = 0;
- *w = '\0';
- w += 8;
- len = atoi(w);
- if ((p1= strchr(w, ':'))) {
- w = p1+ 1;
- }
- printf("%s\n\n\n", r);
+
+ if ((w = strstr(r, "\n\nwrite="))) {
+ int len = 0;
+ *w = '\0';
+ w += 8;
+ len = atoi(w);
+ if ((p1= strchr(w, ':'))) {
+ w = p1+ 1;
+ }
+ printf("%s\n\n\n", r);
#ifdef HAVE_LIBEDIT
- el_deletestr(el, len);
- el_insertstr(el, w);
+ el_deletestr(el, len);
+ el_insertstr(el, w);
#else
#ifdef _MSC_VER
- console_bufferInput(0, len, (char*)buffer, DELETE_REFRESH_OP);
- console_bufferInput(w, (int)strlen(w), (char*)buffer, 0);
+ console_bufferInput(0, len, (char*)buffer, DELETE_REFRESH_OP);
+ console_bufferInput(w, (int)strlen(w), (char*)buffer, 0);
#endif
#endif
- } else {
- printf("%s\n", r);
+ } else {
+ printf("%s\n", r);
#ifdef _MSC_VER
- console_bufferInput(0, 0, (char*)buffer, DELETE_REFRESH_OP);
+ console_bufferInput(0, 0, (char*)buffer, DELETE_REFRESH_OP);
#endif
- }
}
fflush(stdout);
}
if (handle.last_sr_event) {
if (handle.last_sr_event->body) {
printf("%s\n", handle.last_sr_event->body);
- } else if ((err = esl_event_get_header(handle.last_sr_event, "reply-text")) && !strncasecmp(err, "-err", 3)) {
+ } else if ((err = esl_event_get_header(handle.last_sr_event, "reply-text")) && !strncasecmp(err, "-err", 4)) {
printf("Error: %s!\n", err + 4);
}
}
return NULL;
}
- if (newbuffer)
- {
- memcpy(newbuffer, p->buffer, p->offset + 1);
- }
+ memcpy(newbuffer, p->buffer, p->offset + 1);
hooks->deallocate(p->buffer);
}
p->length = newsize;
hooks->deallocate(buffer->buffer);
}
- if (printed != NULL)
- {
- hooks->deallocate(printed);
- }
-
return NULL;
}
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
+#include <assert.h>
#include "esl_cJSON_Utils.h"
{
/* reserve enough memory for a 64 bit integer + '/' and '\0' */
unsigned char *ret = (unsigned char*)malloc(strlen((char*)found) + 23);
+ assert(ret);
/* check if conversion to unsigned long is valid
* This should be eliminated at compile time by dead code elimination
* if size_t is an alias of unsigned long, or if it is bigger */
else if ((type & 0xFF) == cJSON_Object)
{
unsigned char *ret = (unsigned char*)malloc(strlen((char*)found) + cJSONUtils_PointerEncodedstrlen((unsigned char*)obj->string) + 2);
+ assert(ret);
*ret = '/';
cJSONUtils_PointerEncodedstrcpy(ret + 1, (unsigned char*)obj->string);
strcat((char*)ret, (char*)found);
/* malformed patches. */
return 1;
}
- if (patches)
- {
- patches = patches->child;
- }
+
+ patches = patches->child;
+
while (patches)
{
if ((err = cJSONUtils_ApplyPatch(object, patches)))
if (suffix)
{
unsigned char *newpath = (unsigned char*)malloc(strlen((const char*)path) + cJSONUtils_PointerEncodedstrlen(suffix) + 2);
+ assert(newpath);
cJSONUtils_PointerEncodedstrcpy(newpath + sprintf((char*)newpath, "%s/", (const char*)path), suffix);
cJSON_AddItemToObject(patch, "path", cJSON_CreateString((const char*)newpath));
free(newpath);
{
size_t c = 0;
unsigned char *newpath = (unsigned char*)malloc(strlen((const char*)path) + 23); /* Allow space for 64bit int. */
+ assert(newpath);
/* generate patches for all array elements that exist in "from" and "to" */
for (c = 0, from = from->child, to = to->child; from && to; from = from->next, to = to->next, c++)
{
{
/* both object keys are the same */
unsigned char *newpath = (unsigned char*)malloc(strlen((const char*)path) + cJSONUtils_PointerEncodedstrlen((unsigned char*)a->string) + 2);
+ assert(newpath);
cJSONUtils_PointerEncodedstrcpy(newpath + sprintf((char*)newpath, "%s/", path), (unsigned char*)a->string);
/* create a patch for the element */
cJSONUtils_CompareToPatch(patches, newpath, a, b);
end:
- if (server_sock != ESL_SOCK_INVALID) {
- closesocket(server_sock);
- }
+ closesocket(server_sock);
return status;
end:
- if (server_sock != ESL_SOCK_INVALID) {
- closesocket(server_sock);
- }
+ closesocket(server_sock);
return status;
while(ep) {
esl_event_t *e = ep;
ep = ep->next;
- if (e) {
- esl_event_destroy(&e);
- }
+ esl_event_destroy(&e);
}
esl_event_safe_destroy(&handle->last_event);
return ESL_BREAK;
}
- if (activity < 0) {
- handle->connected = 0;
- status = ESL_FAIL;
- } else if (activity > 0 && (activity & ESL_POLL_READ)) {
+ if ((activity & ESL_POLL_READ)) {
if (esl_recv_event(handle, check_q, save_event)) {
status = ESL_FAIL;
}
if (handle->connected) {
if ((activity = esl_wait_sock(handle->sock, 1000, ESL_POLL_READ|ESL_POLL_ERROR)) > 0) {
- if (activity < 0) {
- activity = -1;
- } else if ((activity & ESL_POLL_ERROR)) {
+ if ((activity & ESL_POLL_ERROR)) {
activity = -1;
} else if ((activity & ESL_POLL_READ)) {
if (!(activity = recv(handle->sock, data, datalen, 0))) {
esl_mutex_lock(handle->mutex);
- if (!handle->connected || handle->sock == ESL_SOCK_INVALID) {
- goto fail;
- }
-
esl_event_safe_destroy(&handle->last_ievent);
if (check_q && handle->race_event) {
*e++ = '\0';
while(*e == '\n' || *e == '\r') e++;
- if (hname && hval) {
+ if (hval) {
esl_url_decode(hval);
esl_log(ESL_LOG_DEBUG, "RECV HEADER [%s] = [%s]\n", hname, hval);
if (!strncmp(hval, "ARRAY::", 7)) {
hname = beg;
hval = col = NULL;
- if (hname && (col = strchr(hname, ':'))) {
+ if ((col = strchr(hname, ':'))) {
hval = col + 1;
*col = '\0';
while(*hval == ' ') hval++;
*c = '\0';
- if (hname && hval) {
+ if (hval) {
esl_url_decode(hval);
esl_log(ESL_LOG_DEBUG, "RECV INNER HEADER [%s] = [%s]\n", hname, hval);
if (!strcasecmp(hname, "event-name")) {
esl_mutex_lock(handle->mutex);
-
- if (!handle->connected || handle->sock == ESL_SOCK_INVALID) {
- handle->connected = 0;
- esl_mutex_unlock(handle->mutex);
- return ESL_FAIL;
- }
-
esl_event_safe_destroy(&handle->last_sr_event);
*handle->last_sr_reply = '\0';
goto recv;
}
- if (handle->last_sr_event) {
- hval = esl_event_get_header(handle->last_sr_event, "reply-text");
+ hval = esl_event_get_header(handle->last_sr_event, "reply-text");
- if (!esl_strlen_zero(hval)) {
- snprintf(handle->last_sr_reply, sizeof(handle->last_sr_reply), "%s", hval);
- }
+ if (!esl_strlen_zero(hval)) {
+ snprintf(handle->last_sr_reply, sizeof(handle->last_sr_reply), "%s", hval);
}
}
ESL_DECLARE(esl_size_t) esl_buffer_packet_count(esl_buffer_t *buffer)
{
- char *pe, *p, *e, *head = (char *) buffer->head;
+ char *pe, *p, *e, *head;
esl_size_t x = 0;
esl_assert(buffer != NULL);
+ head = (char *) buffer->head;
+
e = (head + buffer->used);
for (p = head; p && *p && p < e; p++) {
ESL_DECLARE(esl_size_t) esl_buffer_read_packet(esl_buffer_t *buffer, void *data, esl_size_t maxlen)
{
- char *pe, *p, *e, *head = (char *) buffer->head;
+ char *pe, *p, *e, *head;
esl_size_t datalen = 0;
esl_assert(buffer != NULL);
esl_assert(data != NULL);
+ head = (char *) buffer->head;
+
e = (head + buffer->used);
for (p = head; p && *p && p < e; p++) {
#endif
fail:
- if (thread) {
- free(thread);
- }
+ free(thread);
done:
return status;
}