Skip to content

Commit

Permalink
Initialize the extra values to zero
Browse files Browse the repository at this point in the history
When loading an ASCII STL file, the facet extra values are set to random values.

This is because the facet is an uninitialized structure on the stack.
During the load process of a binary STL, these values will be read correctly.
But these values are skipped during the load process of an ASCII STL,
leaving the uninitialized values untouched.

Situations where an ASCII STL is read, but a Binary STL is written would then
result in different output across multiple runs.

An easy fix is to simply set the extra values to zero at the beginning of the
load process. If the load is binary, that value will be overwritten for each
facet. If the load is ASCII then the zero value can be correctly used for each facet.

Fixes #32
Merges #31
  • Loading branch information
obriencj authored and hroncok committed Oct 12, 2019
1 parent 64e86ea commit 43e682d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/stlinit.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ stl_read(stl_file *stl, int first_facet, int first) {
char facet_buffer[12 * sizeof(float)]; char facet_buffer[12 * sizeof(float)];
uint32_t endianswap_buffer; /* for byteswapping operations */ uint32_t endianswap_buffer; /* for byteswapping operations */


facet.extra[0] = 0;
facet.extra[1] = 0;

facet_floats[0] = &facet.normal.x; facet_floats[0] = &facet.normal.x;
facet_floats[1] = &facet.normal.y; facet_floats[1] = &facet.normal.y;
facet_floats[2] = &facet.normal.z; facet_floats[2] = &facet.normal.z;
Expand Down

0 comments on commit 43e682d

Please sign in to comment.