summaryrefslogtreecommitdiff
path: root/lib9p/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib9p/core.c')
-rw-r--r--lib9p/core.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/lib9p/core.c b/lib9p/core.c
index 03cdea5..a0c2f64 100644
--- a/lib9p/core.c
+++ b/lib9p/core.c
@@ -21,16 +21,22 @@
struct lib9p_s lib9p_str(char *s) {
if (!s)
return (struct lib9p_s){0};
+ size_t len = strlen(s);
+ if (len > UINT16_MAX)
+ len = UINT16_MAX;
return (struct lib9p_s){
- .len = strlen(s),
+ .len = LM_SAFEDOWNCAST(uint16_t, len),
.utf8 = s,
};
}
struct lib9p_s lib9p_strn(char *s, size_t maxlen) {
if (maxlen == 0 || !s)
return (struct lib9p_s){0};
+ size_t len = strnlen(s, maxlen);
+ if (len > UINT16_MAX)
+ len = UINT16_MAX;
return (struct lib9p_s){
- .len = strnlen(s, maxlen),
+ .len = LM_SAFEDOWNCAST(uint16_t, len),
.utf8 = s,
};
}
@@ -84,15 +90,15 @@ int _lib9p_errorf(struct lib9p_ctx *ctx,
lib9p_errno_t linux_errno,
#endif
char const *fmt, ...) {
- int n;
+ size_t n;
va_list args;
if (lib9p_ctx_has_error(ctx))
return -1;
va_start(args, fmt);
- n = fmt_vsnprintf(ctx->err_msg, sizeof(ctx->err_msg), fmt, args);
+ n = LM_SAFEDOWNCAST(size_t, fmt_vsnprintf(ctx->err_msg, sizeof(ctx->err_msg), fmt, args));
va_end(args);
- if ((size_t)(n+1) < sizeof(ctx->err_msg))
+ if (n+1 < sizeof(ctx->err_msg))
memset(&ctx->err_msg[n+1], 0, sizeof(ctx->err_msg)-(n+1));
#if CONFIG_9P_ENABLE_9P2000_u || CONFIG_9P_ENABLE_9P2000_L
@@ -212,7 +218,7 @@ void lib9p_Rmsg_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes,
static
bool _lib9p_marshal(const struct _lib9p_send_tentry xxx_table[LIB9P_VER_NUM][0x80],
struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body,
- size_t *ret_iov_cnt, struct iovec *ret_iov, uint8_t *ret_copied) {
+ int *ret_iov_cnt, struct iovec *ret_iov, uint8_t *ret_copied) {
assert_ver(ctx->version);
assert_typ(typ);
struct _marshal_ret ret = {
@@ -281,6 +287,7 @@ uint32_t lib9p_stat_marshal(struct lib9p_ctx *ctx, uint32_t max_net_size, struct
};
if (_lib9p_stat_marshal(&_ctx, obj, &ret))
return 0;
- return ret.net_iov[0].iov_len;
+ assert(ret.net_iov[0].iov_len);
+ return LM_SAFEDOWNCAST(uint32_t, ret.net_iov[0].iov_len);
}
#endif