Skip to content

Commit 1c28d35

Browse files
committed
Suppress more GCC warnings.
Add workaround of `maybe-uninitialized` on gcc.
1 parent 716353c commit 1c28d35

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

src/crate-reader.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2795,7 +2795,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
27952795

27962796
CHECK_MEMORY_USAGE(sizeof(double));
27972797

2798-
double v;
2798+
double v{0.0};
27992799
if (!_sr->read_double(&v)) {
28002800
PUSH_ERROR("Failed to read Double value.");
28012801
return false;

src/image-util.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#pragma GCC diagnostic push
1717
#pragma GCC diagnostic ignored "-Wunused-variable"
1818
#pragma GCC diagnostic ignored "-Wunused-function"
19+
#pragma GCC diagnostic ignored "-Warray-bounds"
1920
#endif
2021

2122
#if !defined(TINYUSDZ_NO_STB_IMAGE_RESIZE_IMPLEMENTATION)

src/linear-algebra.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ value::quatf slerp(const value::quatf &a, const value::quatf &b, const float t)
5151

5252
qret = linalg::slerp(qa, qb, t);
5353

54-
55-
return *(reinterpret_cast<value::quatf *>(&qret));
54+
value::quatf ret;
55+
memcpy(&ret, reinterpret_cast<value::quatf *>(&qret), sizeof(float) * 4);
56+
return ret;
5657
}
5758

5859
value::quatd slerp(const value::quatd &a, const value::quatd &b, const double t) {
@@ -65,9 +66,11 @@ value::quatd slerp(const value::quatd &a, const value::quatd &b, const double t)
6566
memcpy(reinterpret_cast<value::quatd *>(&qb), &b, sizeof(double) * 4);
6667

6768
qret = linalg::slerp(qa, qb, t);
68-
69-
return *(reinterpret_cast<value::quatd *>(&qret));
7069

70+
value::quatd ret;
71+
memcpy(&ret, reinterpret_cast<value::quatd *>(&qret), sizeof(double) * 4);
72+
return ret;
73+
7174
}
7275

7376
float vlength(const value::float3 &a) {

src/stream-reader.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class StreamReader {
293293
return false;
294294
}
295295

296-
float value;
296+
float value{};
297297
if (!read4(reinterpret_cast<int *>(&value))) {
298298
return false;
299299
}
@@ -308,7 +308,7 @@ class StreamReader {
308308
return false;
309309
}
310310

311-
double value;
311+
double value{};
312312
if (!read8(reinterpret_cast<uint64_t *>(&value))) {
313313
return false;
314314
}

src/tydra/render-data.hh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,10 +1060,18 @@ struct UDIMTexture {
10601060
std::unordered_map<uint32_t, int32_t> imageTileIds;
10611061
};
10621062

1063+
// workaround for GCC
1064+
#if defined(__GNUC__) && !defined(__clang__)
1065+
#pragma GCC diagnostic push
1066+
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
1067+
#endif
1068+
10631069
// T or TextureId
10641070
template <typename T>
1065-
struct ShaderParam {
1066-
ShaderParam(const T &t) { value = t; }
1071+
class ShaderParam {
1072+
public:
1073+
ShaderParam() = default;
1074+
ShaderParam(const T &t) : value(t) { }
10671075

10681076
bool is_texture() const { return texture_id >= 0; }
10691077

@@ -1078,12 +1086,14 @@ struct ShaderParam {
10781086
memcpy(&value, &val, sizeof(T));
10791087
}
10801088

1081-
T value;
1089+
//private:
1090+
T value{};
10821091
int32_t texture_id{-1}; // negative = invalid
10831092
};
10841093

10851094
// UsdPreviewSurface
1086-
struct PreviewSurfaceShader {
1095+
class PreviewSurfaceShader {
1096+
public:
10871097
bool useSpecularWorkflow{false};
10881098

10891099
ShaderParam<vec3> diffuseColor{{0.18f, 0.18f, 0.18f}};
@@ -1103,6 +1113,10 @@ struct PreviewSurfaceShader {
11031113
uint64_t handle{0}; // Handle ID for Graphics API. 0 = invalid
11041114
};
11051115

1116+
#if defined(__GNUC__) && !defined(__clang__)
1117+
#pragma GCC diagnostic pop
1118+
#endif
1119+
11061120
// Material + Shader
11071121
struct RenderMaterial {
11081122
std::string name; // elementName in USD (e.g. "pbrMat")

0 commit comments

Comments
 (0)