From 3878c483a59e2799cec3d172e231d03bdace71c1 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Mon, 21 Apr 2025 09:40:17 -0600 Subject: lib9p_core: Indicate what the message size is when ERANGE --- lib9p/core_gen/c_marshal.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib9p/core_gen/c_marshal.py') diff --git a/lib9p/core_gen/c_marshal.py b/lib9p/core_gen/c_marshal.py index 620bdea..322e1ef 100644 --- a/lib9p/core_gen/c_marshal.py +++ b/lib9p/core_gen/c_marshal.py @@ -370,21 +370,21 @@ def gen_c_marshal(versions: set[str], typs: list[idl.UserType]) -> str: # Pass 1 - check size max_size = max(typ.max_size(v) for v in typ.in_versions) + szbits = 32 if max_size > cutil.UINT32_MAX: # SPECIAL (9P2000.e) - ret += get_offset_expr(typ, go_to_end).gen_c( - "uint64_t", "needed_size", "val->", 1, 0 - ) + szbits = 64 + ret += get_offset_expr(typ, go_to_end).gen_c( + f"uint{szbits}_t", "needed_size", "val->", 1, 0 + ) + if szbits > 32: # SPECIAL (9P2000.e) ret += "\tif (needed_size > (uint64_t)(ctx->max_msg_size)) {\n" else: - ret += get_offset_expr(typ, go_to_end).gen_c( - "uint32_t", "needed_size", "val->", 1, 0 - ) ret += "\tif (needed_size > ctx->max_msg_size) {\n" if isinstance(typ, idl.Message): # SPECIAL (disable for stat) - ret += f'\t\tlib9p_errorf(ctx, {c9util.IDENT("ERRNO_L_ERANGE")}, "%s message too large to marshal into %s limit (limit=%"PRIu32")",\n' + ret += f'\t\tlib9p_errorf(ctx, {c9util.IDENT("ERRNO_L_ERANGE")}, "%s message too large to marshal into %s limit (%"PRIu{szbits}" > %"PRIu32")",\n' ret += f'\t\t\t"{typ.typname}",\n' ret += f'\t\t\tctx->version ? "negotiated" : "{'client' if typ.msgid % 2 == 0 else 'server'}",\n' - ret += "\t\t\tctx->max_msg_size);\n" + ret += "\t\t\tneeded_size, ctx->max_msg_size);\n" ret += "\t\treturn true;\n" ret += "\t}\n" -- cgit v1.2.3-2-g168b