Browse code

Prevent check from hanging/crashing when there is a version mismatch.

Show an error on version mismatch, 0.9.8 library with header
from 0.9.6 causes hangs/crashes.

Török Edvin authored on 2010/01/21 01:12:10
Showing 1 changed files
... ...
@@ -516,12 +516,37 @@ void dconf_teardown(void)
516 516
 #endif
517 517
 }
518 518
 
519
+static void check_version_compatible()
520
+{
521
+    /* check 0.9.8 is not ABI compatible with 0.9.6,
522
+     * if by accident you compile with check 0.9.6 header
523
+     * and link with 0.9.8 then check will hang/crash. */
524
+    if ((check_major_version != CHECK_MAJOR_VERSION) ||
525
+	(check_minor_version != CHECK_MINOR_VERSION) ||
526
+	(check_micro_version != CHECK_MICRO_VERSION)) {
527
+	fprintf(stderr, "ERROR: check version mismatch!\n"
528
+		"\tVersion from header: %u.%u.%u\n"
529
+		"\tVersion from library: %u.%u.%u\n"
530
+		"\tMake sure check.h and -lcheck are same version!\n",
531
+		CHECK_MAJOR_VERSION,
532
+		CHECK_MINOR_VERSION,
533
+		CHECK_MICRO_VERSION,
534
+		check_major_version,
535
+		check_minor_version,
536
+		check_micro_version);
537
+	exit(EXIT_FAILURE);
538
+    }
539
+}
519 540
 
520 541
 int main(void)
521 542
 {
522 543
     int nf;
523
-    Suite *s = test_cl_suite();
524
-    SRunner *sr = srunner_create(s);
544
+    Suite *s;
545
+    SRunner *sr;
546
+
547
+    check_version_compatible();
548
+    s = test_cl_suite();
549
+    sr = srunner_create(s);
525 550
 #ifdef CHECK_HAVE_LOOPS
526 551
     srunner_add_suite(sr, test_cli_suite());
527 552
 #else