Skip to content

Commit

Permalink
tidy: Fix potential order-of-initialization problems.
Browse files Browse the repository at this point in the history
A static value in mpegtables.cpp currently depends upon a static
variable initialized in tspacket.cpp, but there is no guarantee of the
order of initialization of the object files.  Convert this value (and
a couple of others) from a "static const" to a "static constexpr" so
that the constant value can be put into the header file and avoid any
order of initialization issues.

https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-interfaces-global-init.html
  • Loading branch information
linuxdude42 committed Jun 17, 2020
1 parent 33f6c3b commit 4622377
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
5 changes: 2 additions & 3 deletions .clang-tidy
Expand Up @@ -110,10 +110,9 @@ Checks: '-*,
# Needs work. ,
-cppcoreguidelines-avoid-goto,
# Good. ,
cppcoreguidelines-init-variables,
# One instance. ,
-cppcoreguidelines-interfaces-global-init,
cppcoreguidelines-interfaces-global-init,
# Tons of warnings. Most complaining that #define should
# become a constexpr. ,
Expand Down
9 changes: 0 additions & 9 deletions mythtv/libs/libmythtv/mpeg/tspacket.cpp
Expand Up @@ -3,15 +3,6 @@
#include <cstdint> // for intptr_t
#include "tspacket.h"

const unsigned int TSHeader::kHeaderSize = 4;

const unsigned int TSPacket::kSize = 188;
const unsigned int TSPacket::kPayloadSize = 188-4;

const unsigned int TSPacket::kDVBEmissionSize = 204;
const unsigned int TSPacket::kISDBEmissionSize = 204;
const unsigned int TSPacket::k8VSBEmissionSize = 208;

const unsigned char TSHeader::kPayloadOnlyHeader[4] =
{
SYNC_BYTE,
Expand Down
12 changes: 6 additions & 6 deletions mythtv/libs/libmythtv/mpeg/tspacket.h
Expand Up @@ -152,7 +152,7 @@ class MTV_PUBLIC TSHeader
const unsigned char* data(void) const { return m_tsData; }
unsigned char* data(void) { return m_tsData; }

static const unsigned int kHeaderSize;
static constexpr unsigned int kHeaderSize {4};
static const unsigned char kPayloadOnlyHeader[4];
private:
unsigned char m_tsData[4] {};
Expand Down Expand Up @@ -217,11 +217,11 @@ class MTV_PUBLIC TSPacket : public TSHeader

QString toString(void) const;

static const unsigned int kSize;
static const unsigned int kPayloadSize;
static const unsigned int kDVBEmissionSize;
static const unsigned int kISDBEmissionSize;
static const unsigned int k8VSBEmissionSize;
static constexpr unsigned int kSize {188};
static constexpr unsigned int kPayloadSize {188-4};
static constexpr unsigned int kDVBEmissionSize {204};
static constexpr unsigned int kISDBEmissionSize {204};
static constexpr unsigned int k8VSBEmissionSize {208};
static const TSPacket *kNullPacket;
private:
unsigned char m_tsPayload[184] {};
Expand Down

0 comments on commit 4622377

Please sign in to comment.