From: Sergey Matveev Date: Thu, 20 Nov 2025 07:12:38 +0000 (+0300) Subject: Do not require offsets to be present X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=fbfeef19f49b01221c39405124078299e94f0c54a392105f760ea2241dbe4e78;p=keks.git Do not require offsets to be present --- diff --git a/c/lib/schema.c b/c/lib/schema.c index 4c819a2..6d056e0 100644 --- a/c/lib/schema.c +++ b/c/lib/schema.c @@ -93,8 +93,8 @@ keksSchemaLens( case KEKSItemRaw: default: return (struct KEKSSchemaErr){ - .offSchema = schema->offsets[idxSchema], - .offData = data->offsets[idxData], + .offSchema = (schema->offsets == NULL) ? 0 : schema->offsets[idxSchema], + .offData = (data->offsets == NULL) ? 0 : data->offsets[idxData], .code = KEKSSchemaErrUnexpectedState, .msg = "unsupported len type", }; @@ -127,8 +127,8 @@ keksSchemaLens( case KEKSItemRaw: default: return (struct KEKSSchemaErr){ - .offSchema = schema->offsets[idxSchema], - .offData = data->offsets[idxData], + .offSchema = (schema->offsets == NULL) ? 0 : schema->offsets[idxSchema], + .offData = (data->offsets == NULL) ? 0 : data->offsets[idxData], .code = KEKSSchemaErrUnexpectedState, .msg = "unsupported len type", }; @@ -162,8 +162,8 @@ keksSchemaCmd( // NOLINT(misc-no-recursion) size_t v = *taken; Eached: idxSchema = origIdxSchema; - err.offSchema = schema->offsets[idxSchema]; - err.offData = data->offsets[idxData]; + err.offSchema = (schema->offsets == NULL) ? 0 : schema->offsets[idxSchema]; + err.offData = (data->offsets == NULL) ? 0 : data->offsets[idxData]; err.code = KEKSSchemaErrInvalid; if (schema->list[idxSchema].atom.v.list.len == 0) { err.code = KEKSSchemaErrInvalidSchema; @@ -197,7 +197,7 @@ Eached: err.msg = "wrong number of args"; return err; } - err.offSchema = schema->offsets[idxSchema]; + err.offSchema = (schema->offsets == NULL) ? 0 : schema->offsets[idxSchema]; switch (schema->list[idxSchema].atom.typ) { case KEKSItemNIL: (*taken) = idxData; @@ -280,7 +280,7 @@ Eached: err.msg = "wrong number of args"; return err; } - err.offSchema = schema->offsets[idxSchema]; + err.offSchema = (schema->offsets == NULL) ? 0 : schema->offsets[idxSchema]; if (schema->list[idxSchema].atom.typ != KEKSItemBin) { err.code = KEKSSchemaErrInvalidSchema; err.msg = "non-bin EQ"; @@ -351,7 +351,7 @@ Eached: return err; } while (idxSchema != 0) { - err.offSchema = schema->offsets[idxSchema]; + err.offSchema = (schema->offsets == NULL) ? 0 : schema->offsets[idxSchema]; if (schema->list[idxSchema].atom.typ != KEKSItemStr) { err.code = KEKSSchemaErrInvalidSchema; err.msg = "non-str TYPE"; @@ -425,8 +425,8 @@ Eached: err.msg = "wrong number of args"; return err; } - err.offSchema = schema->offsets[idxSchema]; - err.offData = data->offsets[v]; + err.offSchema = (schema->offsets == NULL) ? 0 : schema->offsets[idxSchema]; + err.offData = (data->offsets == NULL) ? 0 : data->offsets[v]; int64_t our = 0; int64_t their = 0; struct KEKSSchemaErr errLens = @@ -447,8 +447,8 @@ Eached: err.msg = "wrong number of args"; return err; } - err.offSchema = schema->offsets[idxSchema]; - err.offData = data->offsets[v]; + err.offSchema = (schema->offsets == NULL) ? 0 : schema->offsets[idxSchema]; + err.offData = (data->offsets == NULL) ? 0 : data->offsets[v]; int64_t our = 0; int64_t their = 0; struct KEKSSchemaErr errLens = @@ -465,7 +465,7 @@ Eached: err.msg = "wrong number of args"; return err; } - err.offSchema = schema->offsets[idxSchema]; + err.offSchema = (schema->offsets == NULL) ? 0 : schema->offsets[idxSchema]; if (schema->list[idxSchema].atom.typ != KEKSItemStr) { err.code = KEKSSchemaErrInvalidSchema; err.msg = "non-str SCHEMA"; @@ -481,7 +481,7 @@ Eached: err.msg = "unknown SCHEMA"; return err; } - err.offSchema = schema->offsets[idxSchema]; + err.offSchema = (schema->offsets == NULL) ? 0 : schema->offsets[idxSchema]; err.msg = "SCHEMA"; if (v == SIZE_MAX) { err.code = KEKSSchemaErrNo; @@ -500,7 +500,7 @@ Eached: err.msg = "wrong number of args"; return err; } - err.offSchema = schema->offsets[idxSchema]; + err.offSchema = (schema->offsets == NULL) ? 0 : schema->offsets[idxSchema]; if (schema->list[idxSchema].atom.typ != KEKSItemPint) { err.code = KEKSSchemaErrInvalidSchema; err.msg = "non-int PREC"; @@ -649,8 +649,8 @@ KEKSSchemaValidate( // NOLINT(misc-no-recursion) assert(schema != NULL); assert(data != NULL); struct KEKSSchemaErr err = (struct KEKSSchemaErr){ - .offSchema = schema->offsets[idxSchema], - .offData = data->offsets[idxData], + .offSchema = (schema->offsets == NULL) ? 0 : schema->offsets[idxSchema], + .offData = (data->offsets == NULL) ? 0 : data->offsets[idxData], .code = KEKSSchemaErrInvalid, }; if (schema->list[idxSchema].atom.typ != KEKSItemList) { @@ -659,7 +659,7 @@ KEKSSchemaValidate( // NOLINT(misc-no-recursion) return err; } idxSchema = schema->list[idxSchema].atom.v.list.head; - err.offSchema = schema->offsets[idxSchema]; + err.offSchema = (schema->offsets == NULL) ? 0 : schema->offsets[idxSchema]; struct keksSchemaValidationState state = { .nonExamined = 0, .eachInList = false, @@ -682,7 +682,7 @@ KEKSSchemaValidate( // NOLINT(misc-no-recursion) return errCmd; } idxSchema = schema->list[idxSchema].next; - err.offSchema = schema->offsets[idxSchema]; + err.offSchema = (schema->offsets == NULL) ? 0 : schema->offsets[idxSchema]; } if (state.nonExaminedCheck && state.nonExamined > 0) { err.code = KEKSSchemaErrInvalidData;