Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v1.8.1

* Implemented formatting C-string checks and fixed typo, pr #426.

# v1.8.0

* Added `TI_PROTO_CLIENT_REQ_EMIT_PEER` protocol, pr #414.
Expand Down
7 changes: 5 additions & 2 deletions inc/ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,13 @@ typedef struct ex_s ex_t;
#include <stdarg.h>
#include <string.h>

void ex_set(ex_t * e, ex_enum errnr, const char * errmsg, ...);
void ex_sets(ex_t * e, ex_enum errnr, const char * errmsg);
void ex_set(ex_t * e, ex_enum errnr, const char * errmsg, ...)
__attribute__((format(printf, 3, 4)));
void ex_setv(ex_t * e, ex_enum errnr, const char * errmsg, va_list args);
void ex_setn(ex_t * e, ex_enum errnr, const char * errmsg, size_t n);
void ex_append(ex_t * e, const char * errmsg, ...);
void ex_append(ex_t * e, const char * errmsg, ...)
__attribute__((format(printf, 2, 3)));;
const char * ex_str(ex_enum errnr);

struct ex_s
Expand Down
18 changes: 9 additions & 9 deletions inc/ti/fn/fn.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,15 +559,15 @@ static int fn_call_o_try_n(
{
ex_set(e, EX_LOOKUP_ERROR,
"thing "TI_THING_ID" has no property or method `%.*s`",
thing->id, n, name);
thing->id, (int) n, name);
return e->nr;
}

if (!ti_val_is_closure(val))
{
ex_set(e, EX_TYPE_ERROR,
"property `%.*s` is of type `%s` and is not callable",
n, name, ti_val_str(val));
(int) n, name, ti_val_str(val));
return e->nr;
}

Expand Down Expand Up @@ -602,7 +602,7 @@ static int fn_call_t_try_n(
{
ex_set(e, EX_TYPE_ERROR,
"property `%.*s` is of type `%s` and is not callable",
n, name, ti_val_str(val));
(int) n, name, ti_val_str(val));
return e->nr;
}

Expand All @@ -616,7 +616,7 @@ static int fn_call_t_try_n(
no_prop_err:
ex_set(e, EX_LOOKUP_ERROR,
"type `%s` has no property or method `%.*s`",
thing->via.type->name, n, name);
thing->via.type->name, (int) n, name);
return e->nr;
}

Expand All @@ -637,7 +637,7 @@ static int fn_call_w_try_n(
{
ex_set(e, EX_LOOKUP_ERROR,
"type `%s` has no function `%.*s`",
ti_val_str(query->rval), n, name);
ti_val_str(query->rval), (int) n, name);
return e->nr;
}

Expand All @@ -658,7 +658,7 @@ static int fn_call_w_try_n(
no_method_err:
ex_set(e, EX_LOOKUP_ERROR,
"type `%s` has no method `%.*s`",
type->name, n, name);
type->name, (int) n, name);
return e->nr;
}

Expand All @@ -679,7 +679,7 @@ static int fn_call_f_try_n(

ex_set(e, EX_LOOKUP_ERROR,
"module `%s` has no function `%.*s`",
module->name->str, n, name);
module->name->str, (int) n, name);
return e->nr;
}

Expand Down Expand Up @@ -707,7 +707,7 @@ static int fn_call_m_try_n(

ex_set(e, EX_LOOKUP_ERROR,
"enum `%s` has no function `%.*s`",
member->enum_->name, n, name);
member->enum_->name, (int) n, name);
return e->nr;
}

Expand Down Expand Up @@ -737,7 +737,7 @@ static int fn_call_try_n(

ex_set(e, EX_LOOKUP_ERROR,
"type `%s` has no function `%.*s`",
ti_val_str(query->rval), n, name);
ti_val_str(query->rval), (int) n, name);
return e->nr;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/ti/fn/fnjsonload.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ static int do__f_json_load(ti_query_t * query, cleri_node_t * nd, ex_t * e)
raw->n);
if (yerr)
{
ex_set(e, EX_VALUE_ERROR, (const char *) yerr);
ex_sets(e, EX_VALUE_ERROR, (const char *) yerr);
yajl_free_error(hand, yerr);
}
else
Expand Down
2 changes: 1 addition & 1 deletion inc/ti/fn/fnnewbackup.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static int do__f_new_backup(ti_query_t * query, cleri_node_t * nd, ex_t * e)
"a key file must be configured to use Google Cloud "
"storage; set `gcloud_key_file` in the configuration file or set "
"the environment variable `THINGSDB_GCLOUD_KEY_FILE`"
DOC_NEW_BACKUP, tar_gz_str->n, (char *) tar_gz_str->data);
DOC_NEW_BACKUP);
goto fail0;
}

Expand Down
4 changes: 2 additions & 2 deletions inc/ti/fn/fnremove.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,11 @@ static int do__f_remove_set(ti_query_t * query, cleri_node_t * nd, ex_t * e)
ex_set(e, EX_TYPE_ERROR,
narg == 1
?
"function `remove` expects argument %d to be of type "
"function `remove` expects argument %zu to be of type "
"`"TI_VAL_CLOSURE_S"` or type `"TI_VAL_THING_S"` "
"but got type `%s` instead"DOC_SET_REMOVE
:
"function `remove` expects argument %d to be "
"function `remove` expects argument %zu to be "
"of type `"TI_VAL_THING_S"` "
"but got type `%s` instead"DOC_SET_REMOVE,
narg, ti_val_str(query->rval));
Expand Down
3 changes: 1 addition & 2 deletions inc/ti/fn/fnsort.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ static int do__f_sort(ti_query_t * query, cleri_node_t * nd, ex_t * e)
if (vec_is_sorting())
{
ex_set(e, EX_OPERATION,
"function `sort` cannot be used recursively"DOC_LIST_SORT,
ti_val_str(query->rval));
"function `sort` cannot be used recursively"DOC_LIST_SORT);
return e->nr;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/ti/opr/mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static int opr__mod(ti_val_t * a, ti_val_t ** b, ex_t * e)
{
default:
ex_set(e, EX_TYPE_ERROR,
"`%` not supported between `%s` and `%s`",
"`%%` not supported between `%s` and `%s`",
ti_val_str(a), ti_val_str(*b));
return e->nr;

Expand Down
3 changes: 2 additions & 1 deletion inc/ti/raw.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ ti_raw_t * ti_raw_create(uint8_t tp, const void * raw, size_t n);
ti_raw_t * ti_bytes_from_base64(const void * data, size_t n);
ti_raw_t * ti_str_base64_from_raw(ti_raw_t * src);
ti_raw_t * ti_str_from_ti_string(const char * src, size_t n);
ti_raw_t * ti_str_from_fmt(const char * fmt, ...);
ti_raw_t * ti_str_from_fmt(const char * fmt, ...)
__attribute__((format(printf, 1, 2)));
ti_raw_t * ti_str_from_slice(
ti_raw_t * source,
ssize_t start,
Expand Down
2 changes: 1 addition & 1 deletion inc/ti/val.t.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define TI_KIND_S_SET "$" /* Internally, Set */
#define TI_KIND_S_ERROR "!" /* Internally, Error */
#define TI_KIND_S_WRAP "&" /* Internally, Wrapped thing */
#define TI_KIND_S_MEMBER "%" /* Internally, Enum member */
#define TI_KIND_S_MEMBER "%%" /* Internally, Enum member */
#define TI_KIND_S_DATETIME "'" /* Internally, Date/Time */
#define TI_KIND_S_TIMEVAL "\"" /* Internally, Time value */
#define TI_KIND_S_CLOSURE_OBSOLETE_ "/"
Expand Down
2 changes: 1 addition & 1 deletion inc/ti/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#define TI_VERSION_MAJOR 1
#define TI_VERSION_MINOR 8
#define TI_VERSION_PATCH 0
#define TI_VERSION_PATCH 1

/* The syntax version is used to test compatibility with functions
* using the `ti_nodes_check_syntax()` function */
Expand Down
3 changes: 2 additions & 1 deletion inc/util/buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ int buf_write(buf_t * buf, const char c);
#define buf_append_str(buf__, s__) \
buf_append(buf__, s__, strlen(s__))

int buf_append_fmt(buf_t * buf, const char * s, ...);
int buf_append_fmt(buf_t * buf, const char * s, ...)
__attribute__((format(printf, 2, 3)));

struct buf_s
{
Expand Down
18 changes: 12 additions & 6 deletions inc/util/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@ void logger_init(struct _LOGGER_IO_FILE * ostream, int log_level);
void logger_set_level(int log_level);
const char * logger_level_name(int log_level);

void log_with_level(int log_level, const char * fmt, ...);
void log_with_level(int log_level, const char * fmt, ...)
__attribute__((format(printf, 2, 3)));
void log_line(int log_level, const char * line);
void log__debug(const char * fmt, ...);
void log__info(const char * fmt, ...);
void log__warning(const char * fmt, ...);
void log__error(const char * fmt, ...);
void log__critical(const char * fmt, ...);
void log__debug(const char * fmt, ...)
__attribute__((format(printf, 1, 2)));
void log__info(const char * fmt, ...)
__attribute__((format(printf, 1, 2)));
void log__warning(const char * fmt, ...)
__attribute__((format(printf, 1, 2)));
void log__error(const char * fmt, ...)
__attribute__((format(printf, 1, 2)));
void log__critical(const char * fmt, ...)
__attribute__((format(printf, 1, 2)));

extern logger_t Logger;

Expand Down
2 changes: 1 addition & 1 deletion inc/util/mpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static inline int mp_sbuffer_alloc_init(
return alloc != size && buffer->data == NULL;
}

static int __attribute__((unused))mp_pack_fmt(msgpack_packer * x, const char * fmt, ...)
static int __attribute__((unused))__attribute__((format(printf, 2, 3)))mp_pack_fmt(msgpack_packer * x, const char * fmt, ...)
{
int rc, n;
va_list args1, args2;
Expand Down
5 changes: 5 additions & 0 deletions src/ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ void ex_set(ex_t * e, ex_enum errnr, const char * errmsg, ...)
va_end(args);
}

void ex_sets(ex_t * e, ex_enum errnr, const char * errmsg)
{
ex_setn(e, errnr, errmsg, strlen(errmsg));
}

void ex_setn(ex_t * e, ex_enum errnr, const char * errmsg, size_t n)
{
e->nr = errnr;
Expand Down
2 changes: 1 addition & 1 deletion src/ti.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ int ti_unlock(void)
lock_t rc = lock_unlock(ti.cfg->storage_path);
if (rc != LOCK_REMOVED)
{
log_error(lock_str(rc));
log_error("%s", lock_str(rc));
return -1;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/ti/access.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ int ti_access_check_err(
user->name->n, (char *) user->name->data,
ti_auth_mask_to_str(mask),
prefix,
name_sz, name);
(int) name_sz, name);
}
return e->nr;
}
Expand Down Expand Up @@ -161,11 +161,11 @@ int ti_access_more_check(
ex_set(e, EX_FORBIDDEN,
"user `%.*s` has privileges (`%s`) that user `%.*s` is "
"missing on scope `%s%.*s`",
n->name->n, (char *) n->name->data,
(int) n->name->n, (char *) n->name->data,
ti_auth_mask_to_str(nm),
o->name->n, (char *) o->name->data,
prefix,
name_sz, name);
(int) name_sz, name);
}
return e->nr;
}
Expand All @@ -191,10 +191,10 @@ int ti_access_check_or_err(
ex_set(e, EX_FORBIDDEN,
"user `%.*s` is missing the required privileges (`%s`) "
"on scope `%s%.*s`"DOC_GRANT,
user->name->n, (char *) user->name->data,
(int) user->name->n, (char *) user->name->data,
ti_auth_mask_to_str(mask),
prefix,
name_sz, name);
(int) name_sz, name);
}
return e->nr;
}
Expand Down
10 changes: 5 additions & 5 deletions src/ti/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static void api__data_cb(
if (n < 0)
{
if (n != UV_EOF)
log_error(uv_strerror(n));
log_error("%s", uv_strerror(n));

ti_api_close(ar);
goto done;
Expand Down Expand Up @@ -304,7 +304,7 @@ static int api__header_value_cb(http_parser * parser, const char * at, size_t n)
}

/* invalid content type */
log_debug("unsupported content-type: %.*s", n, at);
log_debug("unsupported content-type: %.*s", (int) n, at);
break;

case TI_API_STATE_AUTHORIZATION:
Expand Down Expand Up @@ -333,7 +333,7 @@ static int api__header_value_cb(http_parser * parser, const char * at, size_t n)
break;
}

log_debug("invalid authorization type: %.*s", n, at);
log_debug("invalid authorization type: %.*s", (int) n, at);
break;
}
return 0;
Expand Down Expand Up @@ -596,7 +596,7 @@ static int api__gen_scope(ti_api_request_t * ar, msgpack_packer * pk)
return mp_pack_fmt(pk, "@n:%d", ar->scope.via.node_id);
case TI_SCOPE_COLLECTION:
return mp_pack_fmt(pk, "@:%.*s",
ar->scope.via.collection_name.sz,
(int) ar->scope.via.collection_name.sz,
ar->scope.via.collection_name.name);
}
return -1;
Expand Down Expand Up @@ -725,7 +725,7 @@ static void api__fwd_cb(ti_req_t * req, ex_enum status)

if (status)
{
ex_set(&ar->e, status, ex_str(status));
ex_sets(&ar->e, status, ex_str(status));
goto fail;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ti/away.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ static void away__work_finish(uv_work_t * UNUSED(work), int status)

int rc;
if (status)
log_error(uv_strerror(status));
log_error("%s", uv_strerror(status));

rc = uv_timer_init(ti.loop, &away__uv_waiter);
if (rc)
Expand Down
6 changes: 3 additions & 3 deletions src/ti/backup.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ char * ti_backup_gcloud_task(ti_backup_t * backup)
"RETURN=$? 2>&1; "
"rm %.*s 2>&1; "
"exit $RETURN;",
fnbuf.len, fnbuf.data,
gsbuf.len, gsbuf.data,
fnbuf.len, fnbuf.data);
(int) fnbuf.len, fnbuf.data,
(int) gsbuf.len, gsbuf.data,
(int) fnbuf.len, fnbuf.data);

if (!backup->work_fn || buf_write(&buf, '\0'))
{
Expand Down
Loading