dvidelabs / flatcc

FlatBuffers Compiler and Library in C for C
Apache License 2.0
632 stars 180 forks source link

monster_test not reproducible #172

Closed madebr closed 3 years ago

madebr commented 3 years ago

When running the monster_test twice in a row, its output (stderr) is not the same. Run the following commands to reproduce:

cd build/test/monster_test
cmake --build . --target monster_test
./monster_test 2>output1.txt
./monster_test 2>output2.txt
diff -u output1.txt output2.txt

The output is:

--- output1.txt 2020-12-21 03:18:43.653230842 +0100
+++ output2.txt 2020-12-21 03:18:46.100244896 +0100
@@ -30,7 +30,7 @@
 00000180  a0 ff ff ff 04 00 00 00  05 00 00 00 4a 6f 6b 65  |............Joke|
 00000190  72 00 00 00 b4 ff ff ff  04 00 00 00 07 00 00 00  |r...............|
 000001a0  54 77 6f 46 61 63 65 00  05 00 00 00 10 00 20 00  |TwoFace....... .|
-000001b0  30 00 40 00 50 00 60 00  70 00 80 00 91 01 91 76  |0.@.P.`.p......v|
+000001b0  30 00 40 00 50 00 60 00  70 00 80 00 91 01 91 ac  |0.@.P.`.p.......|
 000001c0  0a 00 00 00 00 01 02 03  04 05 06 07 08 09 00 00  |................|
 000001d0  09 00 00 00 4d 79 4d 6f  6e 73 74 65 72 00 00 00  |....MyMonster...|
 000001e0  0c 00 08 00 00 00 00 00  00 00 04 00 16 00 10 00  |................|
@@ -70,7 +70,7 @@
 00000180  a0 ff ff ff 04 00 00 00  05 00 00 00 4a 6f 6b 65  |............Joke|
 00000190  72 00 00 00 b4 ff ff ff  04 00 00 00 07 00 00 00  |r...............|
 000001a0  54 77 6f 46 61 63 65 00  05 00 00 00 10 00 20 00  |TwoFace....... .|
-000001b0  30 00 40 00 50 00 60 00  70 00 80 00 91 01 91 73  |0.@.P.`.p......s|
+000001b0  30 00 40 00 50 00 60 00  70 00 80 00 91 01 91 a9  |0.@.P.`.p.......|
 000001c0  0a 00 00 00 00 01 02 03  04 05 06 07 08 09 00 00  |................|
 000001d0  09 00 00 00 4d 79 4d 6f  6e 73 74 65 72 00 00 00  |....MyMonster...|
 000001e0  0c 00 08 00 00 00 00 00  00 00 04 00 16 00 10 00  |................|

The diff is always in the same spot. I can also reproduce this on CI: https://github.com/madebr/flatcc/runs/1586518323?check_suite_focus=true

mikkelfj commented 3 years ago

The monster test is a huge test with many test cases. The first step is to find out which test case drives the output. If the test doesn't already, it would help printing the test title in the output.

The second step is to figure out what might cause it. Most likely it is an uninitialised struct. Flatcc will zero structs and other data, but it also allow you to write more directly in some cases. If the user program doesn't zero structs, there could be uninitialised fields or padding. I'm not sure that is the case here. But it is a possibility.

mikkelfj commented 3 years ago

Also, there is a theoretical possibility that the C compiler uses padding within structs for temporary data when optimising because flatcc uses alignas to arrange structs. Even if a struct is properly memset to zero, the optimiser is allowed to change that. This is a known concern, but never observed.

madebr commented 3 years ago

diff:

--- output1.txt 2020-12-21 03:43:38.028780149 +0100
+++ output2.txt 2020-12-21 03:43:38.044780240 +0100
@@ -30,7 +30,7 @@
 00000180  a0 ff ff ff 04 00 00 00  05 00 00 00 4a 6f 6b 65  |............Joke|
 00000190  72 00 00 00 b4 ff ff ff  04 00 00 00 07 00 00 00  |r...............|
 000001a0  54 77 6f 46 61 63 65 00  05 00 00 00 10 00 20 00  |TwoFace....... .|
-000001b0  30 00 40 00 50 00 60 00  70 00 80 00 91 01 91 81  |0.@.P.`.p.......|
+000001b0  30 00 40 00 50 00 60 00  70 00 80 00 91 01 91 57  |0.@.P.`.p......W|
 000001c0  0a 00 00 00 00 01 02 03  04 05 06 07 08 09 00 00  |................|
 000001d0  09 00 00 00 4d 79 4d 6f  6e 73 74 65 72 00 00 00  |....MyMonster...|
 000001e0  0c 00 08 00 00 00 00 00  00 00 04 00 16 00 10 00  |................|
@@ -70,7 +70,7 @@
 00000180  a0 ff ff ff 04 00 00 00  05 00 00 00 4a 6f 6b 65  |............Joke|
 00000190  72 00 00 00 b4 ff ff ff  04 00 00 00 07 00 00 00  |r...............|
 000001a0  54 77 6f 46 61 63 65 00  05 00 00 00 10 00 20 00  |TwoFace....... .|
-000001b0  30 00 40 00 50 00 60 00  70 00 80 00 91 01 91 7e  |0.@.P.`.p......~|
+000001b0  30 00 40 00 50 00 60 00  70 00 80 00 91 01 91 54  |0.@.P.`.p......T|
 000001c0  0a 00 00 00 00 01 02 03  04 05 06 07 08 09 00 00  |................|
 000001d0  09 00 00 00 4d 79 4d 6f  6e 73 74 65 72 00 00 00  |....MyMonster...|
 000001e0  0c 00 08 00 00 00 00 00  00 00 04 00 16 00 10 00  |................|
Ouput of output1.txt ``` 1 empty monster table: 2 00000000 08 00 00 00 4d 4f 4e 53 e8 ff ff ff 04 00 00 00 |....MONS........| 3 00000010 09 00 00 00 4d 79 4d 6f 6e 73 74 65 72 00 00 00 |....MyMonster...| 4 00000020 0c 00 08 00 00 00 00 00 00 00 04 00 |............| 5 monster table: 6 00000000 0c 00 00 00 4d 4f 4e 53 00 00 00 00 d4 fd ff ff |....MONS........| 7 00000010 50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |P...............| 8 00000020 00 00 80 3f 00 00 00 40 cd cc 4c c0 00 00 00 00 |...?...@..L.....| 9 00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 10 00000040 90 01 00 00 02 00 00 00 78 01 00 00 5c 01 00 00 |........x...\...| 11 00000050 f4 00 00 00 c0 00 00 00 b4 00 00 00 01 00 00 00 |................| 12 00000060 34 01 00 00 1c 00 00 00 00 00 00 00 10 00 00 00 |4...............| 13 00000070 00 00 00 00 00 00 00 00 00 00 00 00 48 fe ff ff |............H...| 14 00000080 68 fe ff ff 78 00 00 00 04 00 00 00 03 00 00 00 |h...x...........| 15 00000090 4c 00 00 00 28 00 00 00 04 00 00 00 9a fe ff ff |L...(...........| 16 000000a0 f4 00 00 00 08 00 00 00 01 00 00 00 08 00 00 00 |................| 17 000000b0 61 6e 79 20 6e 61 6d 65 00 00 00 00 d0 fe ff ff |any name........| 18 000000c0 01 00 00 00 d0 00 00 00 04 00 00 00 08 00 00 00 |................| 19 000000d0 61 6e 79 20 6e 61 6d 65 00 00 00 00 f0 fe ff ff |any name........| 20 000000e0 01 00 00 00 b0 00 00 00 04 00 00 00 08 00 00 00 |................| 21 000000f0 61 6e 79 20 6e 61 6d 65 00 00 00 00 09 00 00 00 |any name........| 22 00000100 74 68 65 20 65 6e 65 6d 79 00 00 00 04 00 00 00 |the enemy.......| 23 00000110 00 01 01 00 03 00 00 00 20 00 00 00 14 00 00 00 |........ .......| 24 00000120 04 00 00 00 06 00 00 00 77 6f 72 6c 64 21 00 00 |........world!..| 25 00000130 02 00 00 00 2c 00 00 00 05 00 00 00 48 65 6c 6c |....,.......Hell| 26 00000140 6f 00 00 00 08 00 00 00 20 00 00 00 48 00 00 00 |o....... ...H...| 27 00000150 30 00 00 00 40 00 00 00 28 00 00 00 38 00 00 00 |0...@...(...8...| 28 00000160 08 00 00 00 1c 00 00 00 88 ff ff ff 04 00 00 00 |................| 29 00000170 08 00 00 00 47 75 6c 6c 69 76 65 72 00 00 00 00 |....Gulliver....| 30 00000180 a0 ff ff ff 04 00 00 00 05 00 00 00 4a 6f 6b 65 |............Joke| 31 00000190 72 00 00 00 b4 ff ff ff 04 00 00 00 07 00 00 00 |r...............| 32 000001a0 54 77 6f 46 61 63 65 00 05 00 00 00 10 00 20 00 |TwoFace....... .| 33 000001b0 30 00 40 00 50 00 60 00 70 00 80 00 91 01 91 81 |0.@.P.`.p.......| 34 000001c0 0a 00 00 00 00 01 02 03 04 05 06 07 08 09 00 00 |................| 35 000001d0 09 00 00 00 4d 79 4d 6f 6e 73 74 65 72 00 00 00 |....MyMonster...| 36 000001e0 0c 00 08 00 00 00 00 00 00 00 04 00 16 00 10 00 |................| 37 000001f0 00 00 00 00 00 00 0c 00 00 00 00 00 00 00 04 00 |................| 38 00000200 08 00 16 00 0d 00 00 00 00 00 00 00 08 00 00 00 |................| 39 00000210 00 00 00 00 0c 00 04 00 1c 00 0c 00 00 00 00 00 |................| 40 00000220 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 41 00000230 00 00 08 00 04 00 04 00 36 00 64 00 14 00 00 00 |........6.d.....| 42 00000240 04 00 34 00 00 00 3c 00 38 00 50 00 54 00 40 00 |..4...<.8.P.T.@.| 43 00000250 48 00 44 00 58 00 00 00 60 00 5c 00 00 00 00 00 |H.D.X...`.\.....| 44 00000260 00 00 00 00 00 00 00 00 00 00 00 00 4c 00 |............L.| 45 monster table with size: 46 00000000 6a 02 00 00 08 00 00 00 4d 4f 4e 53 d4 fd ff ff |j.......MONS....| 47 00000010 50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |P...............| 48 00000020 00 00 80 3f 00 00 00 40 cd cc 4c c0 00 00 00 00 |...?...@..L.....| 49 00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 50 00000040 90 01 00 00 02 00 00 00 78 01 00 00 5c 01 00 00 |........x...\...| 51 00000050 f4 00 00 00 c0 00 00 00 b4 00 00 00 01 00 00 00 |................| 52 00000060 34 01 00 00 1c 00 00 00 00 00 00 00 10 00 00 00 |4...............| 53 00000070 00 00 00 00 00 00 00 00 00 00 00 00 48 fe ff ff |............H...| 54 00000080 68 fe ff ff 78 00 00 00 04 00 00 00 03 00 00 00 |h...x...........| 55 00000090 4c 00 00 00 28 00 00 00 04 00 00 00 9a fe ff ff |L...(...........| 56 000000a0 f4 00 00 00 08 00 00 00 01 00 00 00 08 00 00 00 |................| 57 000000b0 61 6e 79 20 6e 61 6d 65 00 00 00 00 d0 fe ff ff |any name........| 58 000000c0 01 00 00 00 d0 00 00 00 04 00 00 00 08 00 00 00 |................| 59 000000d0 61 6e 79 20 6e 61 6d 65 00 00 00 00 f0 fe ff ff |any name........| 60 000000e0 01 00 00 00 b0 00 00 00 04 00 00 00 08 00 00 00 |................| 61 000000f0 61 6e 79 20 6e 61 6d 65 00 00 00 00 09 00 00 00 |any name........| 62 00000100 74 68 65 20 65 6e 65 6d 79 00 00 00 04 00 00 00 |the enemy.......| 63 00000110 00 01 01 00 03 00 00 00 20 00 00 00 14 00 00 00 |........ .......| 64 00000120 04 00 00 00 06 00 00 00 77 6f 72 6c 64 21 00 00 |........world!..| 65 00000130 02 00 00 00 2c 00 00 00 05 00 00 00 48 65 6c 6c |....,.......Hell| 66 00000140 6f 00 00 00 08 00 00 00 20 00 00 00 48 00 00 00 |o....... ...H...| 67 00000150 30 00 00 00 40 00 00 00 28 00 00 00 38 00 00 00 |0...@...(...8...| 68 00000160 08 00 00 00 1c 00 00 00 88 ff ff ff 04 00 00 00 |................| 69 00000170 08 00 00 00 47 75 6c 6c 69 76 65 72 00 00 00 00 |....Gulliver....| 70 00000180 a0 ff ff ff 04 00 00 00 05 00 00 00 4a 6f 6b 65 |............Joke| 71 00000190 72 00 00 00 b4 ff ff ff 04 00 00 00 07 00 00 00 |r...............| 72 000001a0 54 77 6f 46 61 63 65 00 05 00 00 00 10 00 20 00 |TwoFace....... .| 73 000001b0 30 00 40 00 50 00 60 00 70 00 80 00 91 01 91 7e |0.@.P.`.p......~| 74 000001c0 0a 00 00 00 00 01 02 03 04 05 06 07 08 09 00 00 |................| 75 000001d0 09 00 00 00 4d 79 4d 6f 6e 73 74 65 72 00 00 00 |....MyMonster...| 76 000001e0 0c 00 08 00 00 00 00 00 00 00 04 00 16 00 10 00 |................| 77 000001f0 00 00 00 00 00 00 0c 00 00 00 00 00 00 00 04 00 |................| 78 00000200 08 00 16 00 0d 00 00 00 00 00 00 00 08 00 00 00 |................| 79 00000210 00 00 00 00 0c 00 04 00 1c 00 0c 00 00 00 00 00 |................| 80 00000220 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 81 00000230 00 00 08 00 04 00 04 00 36 00 64 00 14 00 00 00 |........6.d.....| 82 00000240 04 00 34 00 00 00 3c 00 38 00 50 00 54 00 40 00 |..4...<.8.P.T.@.| 83 00000250 48 00 44 00 58 00 00 00 60 00 5c 00 00 00 00 00 |H.D.X...`.\.....| 84 00000260 00 00 00 00 00 00 00 00 00 00 00 00 4c 00 |............L.| 85 Vec3 struct buffer: 86 00000000 10 00 00 00 4d 4f 4e 53 00 00 00 00 00 00 00 00 |....MONS........| 87 00000010 00 00 80 3f 00 00 00 40 00 00 40 40 00 00 00 00 |...?...@..@@....| 88 00000020 cd cc cc cc cc cc 10 40 08 00 aa 0a ef 00 00 00 |.......@........| 89 empty typed monster table: 90 00000000 08 00 00 00 81 f4 0e 33 e8 ff ff ff 04 00 00 00 |.......3........| 91 00000010 09 00 00 00 4d 79 4d 6f 6e 73 74 65 72 00 00 00 |....MyMonster...| 92 00000020 0c 00 08 00 00 00 00 00 00 00 04 00 |............| 93 typed Vec3 struct buffer: 94 00000000 10 00 00 00 d2 3e f5 a8 00 00 00 00 00 00 00 00 |.....>..........| 95 00000010 00 00 80 3f 00 00 00 40 00 00 40 40 00 00 00 00 |...?...@..@@....| 96 00000020 cd cc cc cc cc cc 10 40 08 00 aa 0a ef 00 00 00 |.......@........| 97 clone slice source buffer: 98 00000000 0c 00 00 00 4d 4f 4e 53 00 00 00 00 9c ff ff ff |....MONS........| 99 00000010 50 00 00 00 40 00 00 00 30 00 00 00 00 00 00 00 |P...@...0.......| 100 00000020 33 33 29 c2 00 00 00 00 00 00 00 00 00 00 00 00 |33).............| 101 00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 102 00000040 00 00 00 00 00 00 00 00 02 00 00 00 16 00 00 00 |................| 103 00000050 2c 00 00 00 07 00 00 00 00 01 00 00 01 00 00 00 |,...............| 104 00000060 0a 00 00 00 54 68 65 20 53 6f 75 72 63 65 00 00 |....The Source..| 105 00000070 36 00 34 00 14 00 00 00 00 00 04 00 00 00 00 00 |6.4.............| 106 00000080 00 00 00 00 00 00 0c 00 00 00 00 00 00 00 00 00 |................| 107 00000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 108 000000a0 00 00 00 00 08 00 |......| 109 target buffer of clone: 110 00000000 0c 00 00 00 4d 4f 4e 53 00 00 00 00 f6 fe ff ff |....MONS........| 111 00000010 c0 00 00 00 88 00 00 00 01 00 00 00 4c 00 00 00 |............L...| 112 00000020 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |@...............| 113 00000030 33 33 29 c2 00 00 00 00 00 00 00 00 00 00 00 00 |33).............| 114 00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 115 00000050 04 00 00 00 02 00 00 00 16 00 00 00 2c 00 00 00 |............,...| 116 00000060 04 00 00 00 00 01 00 00 88 ff ff ff 20 00 00 00 |............ ...| 117 00000070 10 00 00 00 04 00 00 00 01 00 00 00 2c 00 00 00 |............,...| 118 00000080 07 00 00 00 00 01 00 00 01 00 00 00 08 00 00 00 |................| 119 00000090 65 20 53 6f 75 72 63 65 00 00 00 00 03 00 00 00 |e Source........| 120 000000a0 20 00 00 00 10 00 00 00 04 00 00 00 03 00 00 00 | ...............| 121 000000b0 54 68 65 00 06 00 00 00 53 6f 75 72 63 65 00 00 |The.....Source..| 122 000000c0 0a 00 00 00 54 68 65 20 53 6f 75 72 63 65 00 00 |....The Source..| 123 000000d0 0a 00 00 00 54 68 65 20 53 6f 75 72 63 65 00 00 |....The Source..| 124 000000e0 36 00 10 00 00 00 00 00 00 00 04 00 00 00 00 00 |6...............| 125 000000f0 00 00 00 00 00 00 0c 00 00 00 00 00 00 00 00 00 |................| 126 00000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 127 00000110 00 00 00 00 08 00 36 00 48 00 24 00 00 00 00 00 |......6.H.$.....| 128 00000120 04 00 00 00 00 00 00 00 0c 00 10 00 44 00 08 00 |............D...| 129 00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 130 00000140 00 00 00 00 00 00 00 00 00 00 14 00 |............| 131 unsorted monster buffer: 132 00000000 08 00 00 00 4d 4f 4e 53 54 ff ff ff 8c 00 00 00 |....MONST.......| 133 00000010 04 00 00 00 05 00 00 00 6c 00 00 00 54 00 00 00 |........l...T...| 134 00000020 38 00 00 00 20 00 00 00 04 00 00 00 84 ff ff ff |8... ...........| 135 00000030 04 00 00 00 08 00 00 00 47 75 6c 6c 69 76 65 72 |........Gulliver| 136 00000040 00 00 00 00 9c ff ff ff 04 00 00 00 05 00 00 00 |................| 137 00000050 41 6c 69 63 65 00 00 00 b0 ff ff ff 04 00 00 00 |Alice...........| 138 00000060 08 00 00 00 47 75 6c 6c 69 76 65 72 00 00 00 00 |....Gulliver....| 139 00000070 c8 ff ff ff 04 00 00 00 05 00 00 00 4a 6f 6b 65 |............Joke| 140 00000080 72 00 00 00 dc ff ff ff 04 00 00 00 07 00 00 00 |r...............| 141 00000090 54 77 6f 46 61 63 65 00 09 00 00 00 4d 79 4d 6f |TwoFace.....MyMo| 142 000000a0 6e 73 74 65 72 00 00 00 0c 00 08 00 00 00 00 00 |nster...........| 143 000000b0 00 00 04 00 1c 00 0c 00 00 00 00 00 00 00 04 00 |................| 144 000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 |................| 145 sorted monster buffer: 146 00000000 08 00 00 00 4d 4f 4e 53 54 ff ff ff 8c 00 00 00 |....MONST.......| 147 00000010 04 00 00 00 05 00 00 00 2c 00 00 00 3c 00 00 00 |........,...<...| 148 00000020 0c 00 00 00 4c 00 00 00 5c 00 00 00 84 ff ff ff |....L...\.......| 149 00000030 04 00 00 00 08 00 00 00 47 75 6c 6c 69 76 65 72 |........Gulliver| 150 00000040 00 00 00 00 9c ff ff ff 04 00 00 00 05 00 00 00 |................| 151 00000050 41 6c 69 63 65 00 00 00 b0 ff ff ff 04 00 00 00 |Alice...........| 152 00000060 08 00 00 00 47 75 6c 6c 69 76 65 72 00 00 00 00 |....Gulliver....| 153 00000070 c8 ff ff ff 04 00 00 00 05 00 00 00 4a 6f 6b 65 |............Joke| 154 00000080 72 00 00 00 dc ff ff ff 04 00 00 00 07 00 00 00 |r...............| 155 00000090 54 77 6f 46 61 63 65 00 09 00 00 00 4d 79 4d 6f |TwoFace.....MyMo| 156 000000a0 6e 73 74 65 72 00 00 00 0c 00 08 00 00 00 00 00 |nster...........| 157 000000b0 00 00 04 00 1c 00 0c 00 00 00 00 00 00 00 04 00 |................| 158 000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 |................| 159 nested flatbuffer: 160 00000000 08 00 00 00 4d 4f 4e 53 ac ff ff ff 40 00 00 00 |....MONS....@...| 161 00000010 08 00 00 00 0a 00 00 00 30 00 00 00 08 00 00 00 |........0.......| 162 00000020 4d 4f 4e 53 f8 ff ff ff 10 00 00 00 0c 00 08 00 |MONS............| 163 00000030 00 00 00 00 00 00 04 00 0f 00 00 00 4d 79 4e 65 |............MyNe| 164 00000040 73 74 65 64 4d 6f 6e 73 74 65 72 00 09 00 00 00 |stedMonster.....| 165 00000050 4d 79 4d 6f 6e 73 74 65 72 00 00 00 20 00 0e 00 |MyMonster... ...| 166 00000060 00 00 00 00 0c 00 04 00 00 00 00 00 00 00 00 00 |................| 167 00000070 00 00 00 00 00 00 00 00 00 00 08 00 |............| 168 nested flatbuffer: 169 00000000 08 00 00 00 4d 4f 4e 53 ac ff ff ff 1c 00 00 00 |....MONS........| 170 00000010 0a 00 00 00 04 00 00 00 09 00 00 00 4d 79 4d 6f |............MyMo| 171 00000020 6e 73 74 65 72 00 00 00 30 00 00 00 08 00 00 00 |nster...0.......| 172 00000030 4d 4f 4e 53 f8 ff ff ff 10 00 00 00 0c 00 08 00 |MONS............| 173 00000040 00 00 00 00 00 00 04 00 0f 00 00 00 4d 79 4e 65 |............MyNe| 174 00000050 73 74 65 64 4d 6f 6e 73 74 65 72 00 20 00 10 00 |stedMonster. ...| 175 00000060 00 00 00 00 08 00 0c 00 00 00 00 00 00 00 00 00 |................| 176 00000070 00 00 00 00 00 00 00 00 00 00 04 00 |............| 177 nested flatbuffer [using _nest()]: 178 00000000 0c 00 00 00 4d 4f 4e 53 00 00 00 00 a4 ff ff ff |....MONS........| 179 00000010 1c 00 00 00 0a 00 00 00 04 00 00 00 09 00 00 00 |................| 180 00000020 4d 79 4d 6f 6e 73 74 65 72 00 00 00 34 00 00 00 |MyMonster...4...| 181 00000030 08 00 00 00 4d 4f 4e 53 e0 ff ff ff 08 00 00 00 |....MONS........| 182 00000040 2a 00 00 00 0f 00 00 00 4d 79 4e 65 73 74 65 64 |*.......MyNested| 183 00000050 4d 6f 6e 73 74 65 72 00 0c 00 0a 00 00 00 08 00 |Monster.........| 184 00000060 00 00 04 00 00 00 00 00 20 00 10 00 00 00 00 00 |........ .......| 185 00000070 08 00 0c 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 186 00000080 00 00 00 00 00 00 04 00 |........| 187 monster table: 188 00000000 0c 00 00 00 4d 4f 4e 53 00 00 00 00 d4 fd ff ff |....MONS........| 189 00000010 50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |P...............| 190 00000020 00 00 80 3f 00 00 00 40 cd cc 4c c0 00 00 00 00 |...?...@..L.....| 191 00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 192 00000040 90 01 00 00 02 00 00 00 78 01 00 00 5c 01 00 00 |........x...\...| 193 00000050 f4 00 00 00 c0 00 00 00 b4 00 00 00 01 00 00 00 |................| 194 00000060 34 01 00 00 1c 00 00 00 00 00 00 00 10 00 00 00 |4...............| 195 00000070 00 00 00 00 00 00 00 00 00 00 00 00 48 fe ff ff |............H...| 196 00000080 68 fe ff ff 78 00 00 00 04 00 00 00 03 00 00 00 |h...x...........| 197 00000090 4c 00 00 00 28 00 00 00 04 00 00 00 9a fe ff ff |L...(...........| 198 000000a0 f4 00 00 00 08 00 00 00 01 00 00 00 08 00 00 00 |................| 199 000000b0 61 6e 79 20 6e 61 6d 65 00 00 00 00 d0 fe ff ff |any name........| 200 000000c0 01 00 00 00 d0 00 00 00 04 00 00 00 08 00 00 00 |................| 201 000000d0 61 6e 79 20 6e 61 6d 65 00 00 00 00 f0 fe ff ff |any name........| 202 000000e0 01 00 00 00 b0 00 00 00 04 00 00 00 08 00 00 00 |................| 203 000000f0 61 6e 79 20 6e 61 6d 65 00 00 00 00 09 00 00 00 |any name........| 204 00000100 74 68 65 20 65 6e 65 6d 79 00 00 00 04 00 00 00 |the enemy.......| 205 00000110 00 01 01 00 03 00 00 00 20 00 00 00 14 00 00 00 |........ .......| 206 00000120 04 00 00 00 06 00 00 00 77 6f 72 6c 64 21 00 00 |........world!..| 207 00000130 02 00 00 00 2c 00 00 00 05 00 00 00 48 65 6c 6c |....,.......Hell| 208 00000140 6f 00 00 00 08 00 00 00 20 00 00 00 48 00 00 00 |o....... ...H...| 209 00000150 30 00 00 00 40 00 00 00 28 00 00 00 38 00 00 00 |0...@...(...8...| 210 00000160 08 00 00 00 1c 00 00 00 88 ff ff ff 04 00 00 00 |................| 211 00000170 08 00 00 00 47 75 6c 6c 69 76 65 72 00 00 00 00 |....Gulliver....| 212 00000180 a0 ff ff ff 04 00 00 00 05 00 00 00 4a 6f 6b 65 |............Joke| 213 00000190 72 00 00 00 b4 ff ff ff 04 00 00 00 07 00 00 00 |r...............| 214 000001a0 54 77 6f 46 61 63 65 00 05 00 00 00 10 00 20 00 |TwoFace....... .| 215 000001b0 30 00 40 00 50 00 60 00 70 00 80 00 91 01 91 0d |0.@.P.`.p.......| 216 000001c0 0a 00 00 00 00 01 02 03 04 05 06 07 08 09 00 00 |................| 217 000001d0 09 00 00 00 4d 79 4d 6f 6e 73 74 65 72 00 00 00 |....MyMonster...| 218 000001e0 0c 00 08 00 00 00 00 00 00 00 04 00 16 00 10 00 |................| 219 000001f0 00 00 00 00 00 00 0c 00 00 00 00 00 00 00 04 00 |................| 220 00000200 08 00 16 00 0d 00 00 00 00 00 00 00 08 00 00 00 |................| 221 00000210 00 00 00 00 0c 00 04 00 1c 00 0c 00 00 00 00 00 |................| 222 00000220 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 223 00000230 00 00 08 00 04 00 04 00 36 00 64 00 14 00 00 00 |........6.d.....| 224 00000240 04 00 34 00 00 00 3c 00 38 00 50 00 54 00 40 00 |..4...<.8.P.T.@.| 225 00000250 48 00 44 00 58 00 00 00 60 00 5c 00 00 00 00 00 |H.D.X...`.\.....| 226 00000260 00 00 00 00 00 00 00 00 00 00 00 00 4c 00 |............L.| 227 cloned monster table: 228 00000000 0c 00 00 00 4d 4f 4e 53 00 00 00 00 0a fe ff ff |....MONS........| 229 00000010 00 00 80 3f 00 00 00 40 cd cc 4c c0 00 00 00 00 |...?...@..L.....| 230 00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 231 00000030 80 01 00 00 6c 01 00 00 04 01 00 00 d0 00 00 00 |....l...........| 232 00000040 c4 00 00 00 34 00 00 00 01 00 00 00 28 01 00 00 |....4.......(...| 233 00000050 10 00 00 00 08 00 00 00 50 00 02 00 5e fe ff ff |........P...^...| 234 00000060 05 00 00 00 10 00 20 00 30 00 40 00 50 00 60 00 |...... .0.@.P.`.| 235 00000070 70 00 80 00 91 01 91 0d 96 fe ff ff 78 00 00 00 |p...........x...| 236 00000080 04 00 00 00 03 00 00 00 4c 00 00 00 28 00 00 00 |........L...(...| 237 00000090 04 00 00 00 c8 fe ff ff 0c 00 00 00 01 00 00 00 |................| 238 000000a0 d4 00 00 00 08 00 00 00 61 6e 79 20 6e 61 6d 65 |........any name| 239 000000b0 00 00 00 00 e8 fe ff ff 0c 00 00 00 01 00 00 00 |................| 240 000000c0 b4 00 00 00 08 00 00 00 61 6e 79 20 6e 61 6d 65 |........any name| 241 000000d0 00 00 00 00 08 ff ff ff 0c 00 00 00 01 00 00 00 |................| 242 000000e0 94 00 00 00 08 00 00 00 61 6e 79 20 6e 61 6d 65 |........any name| 243 000000f0 00 00 00 00 09 00 00 00 74 68 65 20 65 6e 65 6d |........the enem| 244 00000100 79 00 00 00 04 00 00 00 00 01 01 00 03 00 00 00 |y...............| 245 00000110 20 00 00 00 14 00 00 00 04 00 00 00 06 00 00 00 | ...............| 246 00000120 77 6f 72 6c 64 21 00 00 02 00 00 00 2c 00 00 00 |world!......,...| 247 00000130 05 00 00 00 48 65 6c 6c 6f 00 00 00 08 00 00 00 |....Hello.......| 248 00000140 48 00 00 00 30 00 00 00 18 00 00 00 28 00 00 00 |H...0.......(...| 249 00000150 10 00 00 00 20 00 00 00 30 00 00 00 04 00 00 00 |.... ...0.......| 250 00000160 a0 ff ff ff 04 00 00 00 05 00 00 00 4a 6f 6b 65 |............Joke| 251 00000170 72 00 00 00 b4 ff ff ff 04 00 00 00 07 00 00 00 |r...............| 252 00000180 54 77 6f 46 61 63 65 00 c8 ff ff ff 04 00 00 00 |TwoFace.........| 253 00000190 08 00 00 00 47 75 6c 6c 69 76 65 72 00 00 00 00 |....Gulliver....| 254 000001a0 0a 00 00 00 00 01 02 03 04 05 06 07 08 09 00 00 |................| 255 000001b0 09 00 00 00 4d 79 4d 6f 6e 73 74 65 72 00 00 00 |....MyMonster...| 256 000001c0 0c 00 08 00 00 00 00 00 00 00 04 00 16 00 10 00 |................| 257 000001d0 00 00 00 00 00 00 04 00 00 00 00 00 00 00 08 00 |................| 258 000001e0 0c 00 1c 00 0c 00 00 00 00 00 00 00 04 00 00 00 |................| 259 000001f0 00 00 00 00 00 00 00 00 00 00 00 00 08 00 04 00 |................| 260 00000200 04 00 36 00 50 00 04 00 00 00 4c 00 24 00 00 00 |..6.P.....L.$...| 261 00000210 28 00 4e 00 3c 00 40 00 44 00 30 00 2c 00 38 00 |(.N.<.@.D.0.,.8.| 262 00000220 00 00 48 00 4f 00 00 00 00 00 00 00 00 00 00 00 |..H.O...........| 263 00000230 00 00 00 00 00 00 34 00 |......4.| 264 Movie buffer: 265 00000000 08 00 00 00 4d 4f 4e 53 2e ff ff ff 08 00 00 00 |....MONS........| 266 00000010 b0 00 00 00 08 00 00 00 b0 00 00 00 02 00 00 00 |................| 267 00000020 98 00 00 00 0b 00 00 00 84 00 00 00 08 00 00 00 |................| 268 00000030 14 00 00 00 0a 00 00 00 08 02 02 0b 09 09 09 09 |................| 269 00000040 0b 0b 00 00 0a 00 00 00 80 00 00 00 6c 00 00 00 |............l...| 270 00000050 54 00 00 00 44 00 00 00 78 00 00 00 38 00 00 00 |T...D...x...8...| 271 00000060 30 00 00 00 28 00 00 00 18 00 00 00 04 00 00 00 |0...(...........| 272 00000070 0b 00 00 00 79 65 74 20 61 6e 6f 74 68 65 72 00 |....yet another.| 273 00000080 07 00 00 00 61 6e 6f 74 68 65 72 00 02 00 00 00 |....another.....| 274 00000090 01 00 00 00 03 00 00 00 05 00 00 00 6f 74 68 65 |............othe| 275 000000a0 72 00 00 00 d0 ff ff ff 01 00 00 00 04 00 00 00 |r...............| 276 000000b0 4e 65 6d 6f 00 00 00 00 e4 ff ff ff 2a 00 00 00 |Nemo........*...| 277 000000c0 13 00 00 00 00 00 00 00 16 00 00 00 00 00 00 00 |................| 278 000000d0 0a 00 00 00 06 00 08 00 04 00 18 00 2c 00 04 00 |............,...| 279 000000e0 08 00 14 00 18 00 1c 00 20 00 0c 00 10 00 24 00 |........ .....$.| 280 000000f0 28 00 |(.| 281 MultiKeyed buffer: 282 00000000 08 00 00 00 4d 4f 4e 53 f0 fe ff ff 04 00 00 00 |....MONS........| 283 00000010 08 00 00 00 d8 00 00 00 0e ff ff ff 04 00 00 00 |................| 284 00000020 04 00 00 00 40 00 00 00 6c 00 00 00 98 00 00 00 |....@...l.......| 285 00000030 04 00 00 00 34 ff ff ff ec 03 00 00 00 00 00 00 |....4...........| 286 00000040 0c 00 00 00 18 00 00 00 00 00 00 00 08 00 00 00 |................| 287 00000050 67 6f 6f 64 20 64 61 79 00 00 00 00 03 00 00 00 |good day........| 288 00000060 73 69 72 00 64 ff ff ff 04 00 00 00 00 00 00 00 |sir.d...........| 289 00000070 0c 00 00 00 14 00 00 00 00 00 00 00 05 00 00 00 |................| 290 00000080 68 65 6c 6c 6f 00 00 00 06 00 00 00 61 6e 79 6f |hello.......anyo| 291 00000090 6e 65 00 00 94 ff ff ff 0a 00 00 00 00 00 00 00 |ne..............| 292 000000a0 0c 00 00 00 14 00 00 00 00 00 00 00 05 00 00 00 |................| 293 000000b0 68 65 6c 6c 6f 00 00 00 06 00 00 00 61 6e 79 6f |hello.......anyo| 294 000000c0 6e 65 00 00 c4 ff ff ff 2a 00 00 00 00 00 00 00 |ne......*.......| 295 000000d0 08 00 00 00 0c 00 00 00 02 00 00 00 68 69 00 00 |............hi..| 296 000000e0 05 00 00 00 74 68 65 72 65 00 00 00 0d 00 00 00 |....there.......| 297 000000f0 4b 65 79 65 64 20 4d 6f 6e 73 74 65 72 00 00 00 |Keyed Monster...| 298 00000100 0a 00 14 00 0c 00 10 00 04 00 0e 00 08 00 00 00 |................| 299 00000110 00 00 00 00 00 00 04 00 16 00 10 00 00 00 00 00 |................| 300 00000120 00 00 0c 00 00 00 00 00 00 00 04 00 08 00 |..............| ```
mikkelfj commented 3 years ago

So it is one of the early tests. The function monster_test() calls gen_monster()

https://github.com/dvidelabs/flatcc/blob/ce931d0e34b9a4a9dd69939f2d5860c781b42d8b/test/monster_test/monster_test.c#L723-L726

It seems that the variable x is a struct name Test:

https://github.com/dvidelabs/flatcc/blob/ce931d0e34b9a4a9dd69939f2d5860c781b42d8b/test/monster_test/monster_test.fbs#L113

x isn't zero initialised and has a 16 bit and an 8 bit field, and thus 8 bits of padding. The test doesn't zero the struct first so the padding is undefined as I suspected. Changing the declaration of x to x = { 0 } might fix the problem, but the compiler is not required to zero the padding.

mikkelfj commented 3 years ago

Note that this doesn't create incompatible buffers, but the practice of not zero padding is frowned upon, exactly because it results in unexpected diffs, and because it can leak information.

mikkelfj commented 3 years ago

Or better ns(Test_clear(&x)); which will memset the struct.

Excerpt from documentation:

Because padding can carry noise and unintended information, structs should be cleared before assignment - but if used as a source to copy the padding is not copied so only the destination need to be zeroed.

If a struct is nested, the assign operation includes all fields as if the struct was flattened:

typedef struct Plane Plane_t;
struct Plane {
    Vec3_t direction;
    Vec3_t normal;
};
Plane_t plane;
Plane_clear(&plane);
Plane_assign(&plane, 1, 2, 3, 7, 8, 9);
madebr commented 3 years ago

Yup, adding a ns(Test_clear(&x)); prior to assignment makes the test fully reproducible.

mikkelfj commented 3 years ago

Fixed on master.

madebr commented 3 years ago

Thanks for the fix!