Skip to content

Commit 35b0bdd

Browse files
committed
AVRO-4275: [C] Strengthen test assertions to check EINVAL
Assert that the INT64_MIN block count tests fail with the specific EINVAL error code rather than just any non-zero return. This ensures the tests actually exercise the new guard rather than passing due to an unrelated failure downstream. Addresses review feedback on PR #3842. Assisted-by: GitHub Copilot:claude-opus-4.6
1 parent e8b6f74 commit 35b0bdd

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

lang/c/tests/test_avro_4275.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <stdlib.h>
3131
#include <string.h>
3232
#include <stdint.h>
33+
#include <errno.h>
3334
#include <avro.h>
3435

3536
/*
@@ -118,20 +119,21 @@ static int test_array_int64min(void)
118119
return 1;
119120
}
120121

121-
/* This MUST fail gracefully (return error) rather than looping
122-
* unboundedly or triggering undefined behavior. */
122+
/* This MUST fail with EINVAL rather than looping unboundedly or
123+
* triggering undefined behavior from negating INT64_MIN. */
123124
rc = avro_value_read(reader, &value);
124-
if (rc == 0) {
125+
if (rc != EINVAL) {
125126
fprintf(stderr,
126-
"FAIL: INT64_MIN array block count was not rejected\n");
127+
"FAIL: INT64_MIN array block count: expected EINVAL, "
128+
"got rc=%d (%s)\n", rc, avro_strerror());
127129
avro_reader_free(reader);
128130
avro_value_decref(&value);
129131
avro_value_iface_decref(iface);
130132
avro_schema_decref(schema);
131133
return 1;
132134
}
133135

134-
printf("PASS: INT64_MIN array block count rejected: %s\n",
136+
printf("PASS: INT64_MIN array block count rejected with EINVAL: %s\n",
135137
avro_strerror());
136138

137139
avro_reader_free(reader);
@@ -183,19 +185,21 @@ static int test_map_int64min(void)
183185
return 1;
184186
}
185187

186-
/* This MUST fail gracefully. */
188+
/* This MUST fail with EINVAL rather than looping unboundedly or
189+
* triggering undefined behavior from negating INT64_MIN. */
187190
rc = avro_value_read(reader, &value);
188-
if (rc == 0) {
191+
if (rc != EINVAL) {
189192
fprintf(stderr,
190-
"FAIL: INT64_MIN map block count was not rejected\n");
193+
"FAIL: INT64_MIN map block count: expected EINVAL, "
194+
"got rc=%d (%s)\n", rc, avro_strerror());
191195
avro_reader_free(reader);
192196
avro_value_decref(&value);
193197
avro_value_iface_decref(iface);
194198
avro_schema_decref(schema);
195199
return 1;
196200
}
197201

198-
printf("PASS: INT64_MIN map block count rejected: %s\n",
202+
printf("PASS: INT64_MIN map block count rejected with EINVAL: %s\n",
199203
avro_strerror());
200204

201205
avro_reader_free(reader);

0 commit comments

Comments
 (0)