aboutsummaryrefslogtreecommitdiffstats
path: root/pipeline.c
diff options
context:
space:
mode:
Diffstat (limited to 'pipeline.c')
-rw-r--r--pipeline.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/pipeline.c b/pipeline.c
index bead598..a5ddbf2 100644
--- a/pipeline.c
+++ b/pipeline.c
@@ -26,6 +26,10 @@ struct ptx__pipeline_tag
bool handling;
};
+/* returns:
+ * -1 : allocation failed
+ * 0 : nothing was allocated
+ * 1 : pipeline grown */
static int ptx__pipeline_reserve(ptx_pipeline_t *pl, size_t req)
{
assert(pl);
@@ -151,7 +155,8 @@ static ssize_t ptx__pipeline_find_stage(ptx_pipeline_t *ptx, const char *name)
for (size_t idx = 0; idx < ptx->stages_len; ++idx) {
if (!strcmp(ptx->stages[idx].name, name)) {
- return idx;
+ assert(idx <= SSIZE_MAX);
+ return (ssize_t)idx;
}
}
@@ -181,7 +186,7 @@ static int ptx__pipeline_add_at(
}
/* finally, put the stage into the array */
- memmove(pipeline->stages + idx, &temp_stage, sizeof(temp_stage));
+ memcpy(pipeline->stages + idx, &temp_stage, sizeof(temp_stage));
return 0;
}
@@ -203,7 +208,7 @@ int ptx_pipeline_add_after(
ssize_t sidx = ptx__pipeline_find_stage(pipeline, after);
if (sidx < 0) return 0;
- idx = sidx + 1; /* after */
+ idx = (size_t)(sidx + 1); /* after */
} else {
idx = pipeline->stages_len;
}
@@ -235,7 +240,7 @@ int ptx_pipeline_add_before(
ssize_t sidx = ptx__pipeline_find_stage(pipeline, before);
if (sidx < 0) return 0;
- idx = sidx; /* before */
+ idx = (size_t)sidx; /* before */
} else {
idx = 0;
}
@@ -259,7 +264,7 @@ int ptx_pipeline_remove_stage(ptx_pipeline_t *pipeline, const char *name)
if (idx < 0) return 0;
ptx__cleanup_pipeline_stage(pipeline->stages + idx);
- memmove(pipeline->stages + idx, pipeline->stages + idx + 1, sizeof(pipeline->stages[0]) * (pipeline->stages_len - idx));
+ memmove(pipeline->stages + idx, pipeline->stages + idx + 1, sizeof(pipeline->stages[0]) * (pipeline->stages_len - (size_t)idx - 1));
--pipeline->stages_len;
return 1;
@@ -277,7 +282,7 @@ const char *ptx_pipeline_ctx_get_name(const ptx_pipeline_ctx_t *ctx)
return ctx->pipeline->stages[ctx->curidx].name;
}
-int ptx_pipeline_ctx_next(const ptx_pipeline_ctx_t *ctx, void *nextdata, size_t nextsize)
+int ptx_pipeline_ctx_next(const ptx_pipeline_ctx_t *ctx, const void *nextdata, size_t nextsize)
{
assert(ctx->curidx + 1 < ctx->pipeline->stages_len);
@@ -290,7 +295,7 @@ int ptx_pipeline_ctx_next(const ptx_pipeline_ctx_t *ctx, void *nextdata, size_t
return (*new_ctx.pipeline->stages[new_ctx.curidx].impl.handler)(&new_ctx, nextdata, nextsize);
}
-int ptx_pipeline_handle(ptx_pipeline_t *pipeline, void *data, size_t sz)
+int ptx_pipeline_handle(ptx_pipeline_t *pipeline, const void *data, size_t sz)
{
assert(pipeline);
assert(!pipeline->handling);