Commit 747db471 authored by Flavio Ceolin's avatar Flavio Ceolin Committed by Anas Nashif
Browse files

lib: printk: Code guideline fixes



Fixes violations code guideline related with essential types rules:

- Ensure computations are done in the destination precision
- Avoid mixing characters with integers

Signed-off-by: default avatarFlavio Ceolin <flavio.ceolin@intel.com>
Signed-off-by: default avatarAbramo Bagnara <abramo.bagnara@bugseng.com>
parent ec69bda0
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ static int buf_char_out(int c, void *ctx_p)
	struct buf_out_context *ctx = ctx_p;

	ctx->count++;
	ctx->buf[ctx->buf_count++] = c;
	ctx->buf[ctx->buf_count++] = (char)c;
	if (ctx->buf_count == CONFIG_PRINTK_BUFFER_SIZE) {
		buf_flush(ctx);
	}
@@ -166,7 +166,7 @@ void z_impl_k_str_out(char *c, size_t n)
#endif

	for (i = 0; i < n; i++) {
		_char_out(c[i]);
		_char_out((int)c[i]);
	}

#ifdef CONFIG_PRINTK_SYNC
@@ -225,8 +225,8 @@ void printk(const char *fmt, ...)

struct str_context {
	char *str;
	int max;
	int count;
	size_t max;
	size_t count;
};

static int str_out(int c, struct str_context *ctx)
@@ -239,7 +239,7 @@ static int str_out(int c, struct str_context *ctx)
	if (ctx->count == ctx->max - 1) {
		ctx->str[ctx->count++] = '\0';
	} else {
		ctx->str[ctx->count++] = c;
		ctx->str[ctx->count++] = (char)c;
	}

	return c;
@@ -267,5 +267,5 @@ int vsnprintk(char *str, size_t size, const char *fmt, va_list ap)
		str[ctx.count] = '\0';
	}

	return ctx.count;
	return (int)ctx.count;
}