summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHauke Mehrtens <hauke@hauke-m.de>2020-10-04 17:14:48 +0200
committerPetr Štetiar <ynezz@true.cz>2020-10-06 08:31:44 +0200
commit7f574273180ac940c57da0f28c26a5274c165e48 (patch)
tree2757ba79df98f8885e6309c90d35540e13615d71
parent19770b6949b9a95038f3216da773204eadfdd6bc (diff)
downloaduci-7f574273180ac940c57da0f28c26a5274c165e48.tar.gz
file: use size_t for position and pointer
The bufsz variable is used to store the size of the buf memory region and pos is used to index a position in this memory. Use size_t for these variables in the internal handling instaed of int to not break with big files. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
-rw-r--r--file.c14
-rw-r--r--libuci.c2
-rw-r--r--uci_internal.h8
3 files changed, 12 insertions, 12 deletions
diff --git a/file.c b/file.c
index ce1acb2..c9b23d4 100644
--- a/file.c
+++ b/file.c
@@ -38,11 +38,11 @@
/*
* Fetch a new line from the input stream and resize buffer if necessary
*/
-__private void uci_getln(struct uci_context *ctx, int offset)
+__private void uci_getln(struct uci_context *ctx, size_t offset)
{
struct uci_parse_context *pctx = ctx->pctx;
char *p;
- int ofs;
+ size_t ofs;
if (pctx->buf == NULL) {
pctx->buf = uci_malloc(ctx, LINEBUF);
@@ -112,7 +112,7 @@ static void skip_whitespace(struct uci_context *ctx)
pctx->pos += 1;
}
-static inline void addc(struct uci_context *ctx, int *pos_dest, int *pos_src)
+static inline void addc(struct uci_context *ctx, size_t *pos_dest, size_t *pos_src)
{
struct uci_parse_context *pctx = ctx->pctx;
@@ -124,7 +124,7 @@ static inline void addc(struct uci_context *ctx, int *pos_dest, int *pos_src)
/*
* parse a double quoted string argument from the command line
*/
-static void parse_double_quote(struct uci_context *ctx, int *target)
+static void parse_double_quote(struct uci_context *ctx, size_t *target)
{
struct uci_parse_context *pctx = ctx->pctx;
char c;
@@ -159,7 +159,7 @@ static void parse_double_quote(struct uci_context *ctx, int *target)
/*
* parse a single quoted string argument from the command line
*/
-static void parse_single_quote(struct uci_context *ctx, int *target)
+static void parse_single_quote(struct uci_context *ctx, size_t *target)
{
struct uci_parse_context *pctx = ctx->pctx;
char c;
@@ -188,7 +188,7 @@ static void parse_single_quote(struct uci_context *ctx, int *target)
/*
* parse a string from the command line and detect the quoting style
*/
-static void parse_str(struct uci_context *ctx, int *target)
+static void parse_str(struct uci_context *ctx, size_t *target)
{
struct uci_parse_context *pctx = ctx->pctx;
bool next = true;
@@ -237,7 +237,7 @@ done:
static int next_arg(struct uci_context *ctx, bool required, bool name, bool package)
{
struct uci_parse_context *pctx = ctx->pctx;
- int val, ptr;
+ size_t val, ptr;
skip_whitespace(ctx);
val = ptr = pctx_pos(pctx);
diff --git a/libuci.c b/libuci.c
index 140edf2..786d035 100644
--- a/libuci.c
+++ b/libuci.c
@@ -148,7 +148,7 @@ uci_get_errorstr(struct uci_context *ctx, char **dest, const char *prefix)
err = UCI_ERR_UNKNOWN;
if (ctx && ctx->pctx && (err == UCI_ERR_PARSE)) {
- snprintf(error_info, sizeof(error_info) - 1, " (%s) at line %d, byte %d",
+ snprintf(error_info, sizeof(error_info) - 1, " (%s) at line %d, byte %zu",
(ctx->pctx->reason ? ctx->pctx->reason : "unknown"),
ctx->pctx->line, ctx->pctx->byte);
}
diff --git a/uci_internal.h b/uci_internal.h
index f00b394..3a94dbb 100644
--- a/uci_internal.h
+++ b/uci_internal.h
@@ -23,7 +23,7 @@ struct uci_parse_context
/* error context */
const char *reason;
int line;
- int byte;
+ size_t byte;
/* private: */
struct uci_package *package;
@@ -32,8 +32,8 @@ struct uci_parse_context
FILE *file;
const char *name;
char *buf;
- int bufsz;
- int pos;
+ size_t bufsz;
+ size_t pos;
};
#define pctx_pos(pctx) ((pctx)->pos)
#define pctx_str(pctx, i) (&(pctx)->buf[(i)])
@@ -54,7 +54,7 @@ __private struct uci_package *uci_alloc_package(struct uci_context *ctx, const c
__private FILE *uci_open_stream(struct uci_context *ctx, const char *filename, const char *origfilename, int pos, bool write, bool create);
__private void uci_close_stream(FILE *stream);
-__private void uci_getln(struct uci_context *ctx, int offset);
+__private void uci_getln(struct uci_context *ctx, size_t offset);
__private void uci_parse_error(struct uci_context *ctx, char *reason);
__private void uci_alloc_parse_context(struct uci_context *ctx);