Skip to content

Commit

Permalink
cppcheck: Reduce the scope of variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdude42 committed Sep 20, 2020
1 parent b75f4e3 commit 698c347
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 66 deletions.
2 changes: 1 addition & 1 deletion mythtv/libs/libmyth/audio/audiooutputaudiotrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ void AudioOutputAudioTrack::WriteAudio(unsigned char* aubuf, int size)

int AudioOutputAudioTrack::GetBufferedOnSoundcard(void) const
{
bool exception=false;
QAndroidJniEnvironment env;
int buffered (0);
if (m_audioTrack)
Expand All @@ -249,6 +248,7 @@ int AudioOutputAudioTrack::GetBufferedOnSoundcard(void) const
// is data already played that is still in the "Audio circular buffer"
buffered
= m_audioTrack->callMethod<jint>("getBufferedBytes");
bool exception=false;
ANDROID_EXCEPTION_CHECK
if (exception)
buffered = 0;
Expand Down
6 changes: 2 additions & 4 deletions mythtv/libs/libmyth/audio/audiooutputca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,6 @@ void CoreAudioData::ResetStream(AudioStreamID s)
currentFormat.mFormatID == kAudioFormat60958AC3)
{
AudioStreamRangedVec formats = FormatsList(s);
bool streamReset = false;


if (formats.empty())
Expand All @@ -1728,16 +1727,15 @@ void CoreAudioData::ResetStream(AudioStreamID s)
for (auto format : formats) {
if (format.mFormat.mFormatID == kAudioFormatLinearPCM)
{
err = AudioObjectSetPropertyData(s, &pa, 0, nullptr,
sizeof(format), &(format.mFormat));
err = AudioObjectSetPropertyData(s, &pa, 0, nullptr,
sizeof(format), &(format.mFormat));
if (err != noErr)
{
Warn(QString("ResetStream: could not set physical format: [%1]")
.arg(OSS_STATUS(err)));
continue;
}

streamReset = true;
sleep(1); // For the change to take effect
}
}
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmyth/audio/audiooutputpulse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,14 +567,14 @@ bool AudioOutputPulseAudio::ConnectPlaybackStream(void)
pa_stream_connect_playback(m_pstream, nullptr, &m_bufferSettings,
(pa_stream_flags_t)flags, nullptr, nullptr);

pa_context_state_t cstate = PA_CONTEXT_UNCONNECTED;
pa_stream_state_t sstate = PA_STREAM_UNCONNECTED;
bool connected = false;
bool failed = false;

while (!(connected || failed))
{
switch (cstate = pa_context_get_state(m_pcontext))
pa_context_state_t cstate = pa_context_get_state(m_pcontext);
switch (cstate)
{
case PA_CONTEXT_FAILED:
case PA_CONTEXT_TERMINATED:
Expand Down
6 changes: 2 additions & 4 deletions mythtv/libs/libmythbase/unzip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,10 @@ UnZip::ErrorCode UnZip::extractFile(const QString& filename, QIODevice* dev, Ext
UnZip::ErrorCode UnZip::extractFiles(const QStringList& filenames, const QString& dirname, ExtractionOptions options)
{
QDir dir(dirname);
ErrorCode ec = Ok;

for (QStringList::ConstIterator itr = filenames.constBegin(); itr != filenames.constEnd(); ++itr)
{
ec = extractFile(*itr, dir, options);
ErrorCode ec = extractFile(*itr, dir, options);
if (ec == FileNotFound)
continue;
if (ec != Ok)
Expand All @@ -480,11 +479,10 @@ UnZip::ErrorCode UnZip::extractFiles(const QStringList& filenames, const QString
*/
UnZip::ErrorCode UnZip::extractFiles(const QStringList& filenames, const QDir& dir, ExtractionOptions options)
{
ErrorCode ec = Ok;

for (QStringList::ConstIterator itr = filenames.constBegin(); itr != filenames.constEnd(); ++itr)
{
ec = extractFile(*itr, dir, options);
ErrorCode ec = extractFile(*itr, dir, options);
if (ec == FileNotFound)
continue;
if (ec != Ok)
Expand Down
5 changes: 2 additions & 3 deletions mythtv/libs/libmythtv/captions/xine_demux_sputext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ static inline void trail_space(std::string& str)
*
*/
static char *read_line_from_input(demux_sputext_t *demuxstr, std::string& line) {
off_t nread = 0;

line.reserve(LINE_LEN);
if ((line.capacity() - demuxstr->buf.size()) > 512) {
nread = line.capacity() - demuxstr->buf.size();
off_t nread = line.capacity() - demuxstr->buf.size();
nread = std::min(nread, demuxstr->rbuffer_len - demuxstr->rbuffer_cur);
if (nread < 0) {
printf("read failed.\n");
Expand Down Expand Up @@ -653,7 +652,6 @@ static subtitle_t *sub_read_line_jacobsub(demux_sputext_t *demuxstr, subtitle_t
int seconds = 0;
int delta = 0;
uint32_t units = s_jacoShift;
int inverter = 1;
switch (toupper(line1[1])) {
case 'S':
if (isalpha(line1[2])) {
Expand All @@ -662,6 +660,7 @@ static subtitle_t *sub_read_line_jacobsub(demux_sputext_t *demuxstr, subtitle_t
delta = 2;
}
if (sscanf(&line1[delta], "%d", &hours)) {
int inverter = 1;
if (hours < 0) {
hours *= -1;
inverter = -1;
Expand Down
3 changes: 1 addition & 2 deletions mythtv/libs/libmythtv/eitfixup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,10 +1112,9 @@ void EITFixUp::FixUK(DBEventEIT &event)
!event.m_title.startsWith("The X-Files"))
{
int position1 = -1;
int position2 = -1;
if ((position1=event.m_description.indexOf(kUKTime)) != -1)
{
position2 = event.m_description.indexOf(kUKColonPeriod);
int position2 = event.m_description.indexOf(kUKColonPeriod);
if ((position2>=0) && (position2 < (position1-2)))
SetUKSubtitle(event);
}
Expand Down
3 changes: 1 addition & 2 deletions mythtv/libs/libmythtv/jobqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ void JobQueue::ProcessQueue(void)
QString message;
QMap<int, JobQueueEntry> jobs;
bool atMax = false;
bool inTimeWindow = true;
QMap<int, RunningJobInfo>::Iterator rjiter;

QMutexLocker locker(&m_queueThreadCondLock);
Expand Down Expand Up @@ -208,7 +207,7 @@ void JobQueue::ProcessQueue(void)

if (!jobs.empty())
{
inTimeWindow = InJobRunWindow();
bool inTimeWindow = InJobRunWindow();
for (const auto & job : qAsConst(jobs))
{
int status = job.status;
Expand Down
44 changes: 18 additions & 26 deletions mythtv/libs/libmythtv/mpeg/HEVCParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,14 +585,13 @@ bool HEVCParser::profileTierLevel(GetBitContext *gb,
int maxNumSubLayersMinus1)
{
int i = 0;
int j = 0;

if (profilePresentFlag)
{
get_bits(gb, 2); // general_profile_space u(2);
get_bits1(gb); // general_tier_flag u(1)
get_bits(gb, 5); // general_profile_idc u(5);
for (j = 0; j < 32; ++j)
for (int j = 0; j < 32; ++j)
get_bits1(gb); // general_profile_compatibility_flag[j] u(1);

/*
Expand Down Expand Up @@ -772,7 +771,7 @@ bool HEVCParser::profileTierLevel(GetBitContext *gb,
get_bits1(gb); //sub_layer_tier_flag[i] u(1)
get_bits(gb, 5); // sub_layer_profile_idc[i] u(5);

for (j = 0; j < 32; ++j)
for (int j = 0; j < 32; ++j)
get_bits1(gb); //sub_layer_profile_compatibility_flag[i][j] u(1)

get_bits1(gb); //sub_layer_progressive_source_flag[i] u(1)
Expand Down Expand Up @@ -924,13 +923,11 @@ static bool scalingListData(GetBitContext * gb,
bool use_default)
{
uint8_t sizeId = 0;
uint matrixId = 0;
uint8_t size = 0;
uint8_t i = 0;

for (sizeId = 0; sizeId < 4; ++sizeId)
{
for (matrixId = 0; matrixId < ((sizeId == 3) ? 2 : 6); ++matrixId)
for (uint matrixId = 0; matrixId < ((sizeId == 3) ? 2 : 6); ++matrixId)
{
std::vector<int16_t> scaling_list_dc_coef_minus8 {};
uint8_t *sl = nullptr;
Expand Down Expand Up @@ -1030,7 +1027,7 @@ static bool scalingListData(GetBitContext * gb,
#endif
}

for (i = 0; i < size; ++i)
for (uint8_t i = 0; i < size; ++i)
{
get_se_golomb(gb); // scaling_list_delta_coef se(v)
#if 0 // Unneeded
Expand Down Expand Up @@ -1064,15 +1061,11 @@ static bool shortTermRefPicSet(GetBitContext * gb, int stRPSIdx,
std::array<HEVCParser::ShortTermRefPicSet,65> & stRPS,
uint8_t max_dec_pic_buffering_minus1)
{
int16_t deltaRPS = 0;
std::array<bool,16> use_delta_flag { false };
std::array<bool,16> used_by_curr_pic_flag { false };
std::array<uint32_t,16> delta_poc_s0_minus1 { 0 };
std::array<uint32_t,16> delta_poc_s1_minus1 { 0 };
uint i = 0;
uint j = 0;
int k = 0;
int dPoc = 0;

/* 7.4.8 inter_ref_pic_set_prediction_flag equal to 1 specifies
that the stRPSIdx-th candidate short-term RPS is predicted from
Expand All @@ -1086,6 +1079,8 @@ static bool shortTermRefPicSet(GetBitContext * gb, int stRPSIdx,

if (inter_ref_pic_set_prediction_flag)
{
int16_t deltaRPS = 0;

/*
delta_idx_minus1 plus 1 specifies the difference between the
value of stRPSIdx and the index, into the list of the
Expand Down Expand Up @@ -1113,7 +1108,7 @@ static bool shortTermRefPicSet(GetBitContext * gb, int stRPSIdx,
int RefRPSIdx = stRPSIdx - (delta_idx_minus1 + 1);
HEVCParser::ShortTermRefPicSet *RefRPS = &stRPS[RefRPSIdx];

for (j = 0; j <= RefRPS->NumDeltaPocs; ++j)
for (int j = 0; j <= RefRPS->NumDeltaPocs; ++j)
{
/*
use_delta_flag[ j ] equal to 1 specifies that the
Expand All @@ -1132,9 +1127,9 @@ static bool shortTermRefPicSet(GetBitContext * gb, int stRPSIdx,

/* 7.4.8 Short-term reference picture set semantics */
i = 0;
for (k = (RefRPS->NumPositivePics - 1); k >= 0; --k)
for (int k = (RefRPS->NumPositivePics - 1); k >= 0; --k)
{
dPoc = RefRPS->DeltaPocS1[k] + deltaRPS;
int dPoc = RefRPS->DeltaPocS1[k] + deltaRPS;
if (dPoc < 0 && use_delta_flag[RefRPS->NumNegativePics + k])
{
stRPS[stRPSIdx].DeltaPocS0[i] = dPoc;
Expand All @@ -1150,9 +1145,9 @@ static bool shortTermRefPicSet(GetBitContext * gb, int stRPSIdx,
used_by_curr_pic_flag[RefRPS->NumDeltaPocs];
}

for (j = 0; j < RefRPS->NumNegativePics; ++j)
for (int j = 0; j < RefRPS->NumNegativePics; ++j)
{
dPoc = RefRPS->DeltaPocS0[j] + deltaRPS;
int dPoc = RefRPS->DeltaPocS0[j] + deltaRPS;
if (dPoc < 0 && use_delta_flag[j])
{
stRPS[stRPSIdx].DeltaPocS0[i] = dPoc;
Expand All @@ -1162,9 +1157,9 @@ static bool shortTermRefPicSet(GetBitContext * gb, int stRPSIdx,
stRPS[stRPSIdx].NumNegativePics = i;

i = 0;
for (k = (RefRPS->NumNegativePics - 1); k >= 0; --k)
for (int k = (RefRPS->NumNegativePics - 1); k >= 0; --k)
{
dPoc = RefRPS->DeltaPocS0[k] + deltaRPS;
int dPoc = RefRPS->DeltaPocS0[k] + deltaRPS;
if (dPoc > 0 && use_delta_flag[k])
{
stRPS[stRPSIdx].DeltaPocS1[i] = dPoc;
Expand All @@ -1179,9 +1174,9 @@ static bool shortTermRefPicSet(GetBitContext * gb, int stRPSIdx,
used_by_curr_pic_flag[RefRPS->NumDeltaPocs];
}

for (j = 0; j < RefRPS->NumPositivePics; ++j)
for (int j = 0; j < RefRPS->NumPositivePics; ++j)
{
dPoc = RefRPS->DeltaPocS1[j] + deltaRPS;
int dPoc = RefRPS->DeltaPocS1[j] + deltaRPS;
if (dPoc > 0 && use_delta_flag[RefRPS->NumNegativePics + j])
{
stRPS[stRPSIdx].DeltaPocS1[i] = dPoc;
Expand Down Expand Up @@ -1252,8 +1247,6 @@ bool HEVCParser::parseSliceSegmentLayer(GetBitContext *gb)
*/
bool HEVCParser::parseSliceSegmentHeader(GetBitContext *gb)
{
uint i = 0;
uint16_t slice_pic_order_cnt_lsb = 0;
bool dependent_slice_segment_flag = false; // check!

m_firstSliceSegmentInPicFlag = get_bits1(gb);
Expand Down Expand Up @@ -1302,7 +1295,7 @@ bool HEVCParser::parseSliceSegmentHeader(GetBitContext *gb)
// CuQpDeltaVal = 0;
if (!dependent_slice_segment_flag)
{
for (i = 0; i < pps->num_extra_slice_header_bits; ++i)
for (int i = 0; i < pps->num_extra_slice_header_bits; ++i)
{
get_bits1(gb); // slice_reserved_flag[i]; // u(1)
}
Expand All @@ -1323,7 +1316,7 @@ bool HEVCParser::parseSliceSegmentHeader(GetBitContext *gb)
}
else
{
slice_pic_order_cnt_lsb =
uint16_t slice_pic_order_cnt_lsb =
get_bits(gb, sps->log2_max_pic_order_cnt_lsb); // u(v)

/*
Expand Down Expand Up @@ -1839,7 +1832,6 @@ bool HEVCParser::parseSPS(GetBitContext *gb)
bool HEVCParser::parseVPS(GetBitContext *gb)
{
uint i = 0;
uint j = 0;

uint8_t vps_id = get_bits(gb, 4); // vps_video_parameter_set_id u(4)
get_bits1(gb); // vps_base_layer_internal_flag u(1)
Expand Down Expand Up @@ -1890,7 +1882,7 @@ bool HEVCParser::parseVPS(GetBitContext *gb)
uint vps_num_layer_sets_minus1 = get_ue_golomb(gb); // ue(v)
for (i = 1; i <= vps_num_layer_sets_minus1; ++i)
{
for (j = 0; j <= vps_max_layer_id; ++j)
for (int j = 0; j <= vps_max_layer_id; ++j)
{
get_bits1(gb); // layer_id_included_flag[i][j] u(1)
}
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/tv_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12898,7 +12898,7 @@ void TV::ShowOSDPromptDeleteRecording(PlayerContext *ctx, const QString& title,
{
LOG(VB_GENERAL, LOG_ERR,
"This program cannot be deleted at this time.");
ProgramInfo pginfo(*ctx->m_playingInfo);
ProgramInfo pginfo(*ctx->m_playingInfo); // cppcheck-suppress variableScope
ctx->UnlockPlayingInfo(__FILE__, __LINE__);

OSD *osd = GetOSDLock(ctx);
Expand Down
5 changes: 2 additions & 3 deletions mythtv/libs/libmythtv/tv_rec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ RecStatus::Type TVRec::StartRecording(ProgramInfo *pginfo)
.arg(rcinfo->toString(ProgramInfo::kTitleSubtitle)));

QMutexLocker lock(&m_stateChangeLock);
QString msg("");

if (m_recStatus != RecStatus::Failing)
SetRecordingStatus(RecStatus::Aborted, __LINE__);
Expand All @@ -430,7 +429,7 @@ RecStatus::Type TVRec::StartRecording(ProgramInfo *pginfo)
m_recordEndTime = m_curRecording->GetRecordingEndTime()
.addSecs(post_roll_seconds);

msg = QString("updating recording: %1 %2 %3 %4")
QString msg = QString("updating recording: %1 %2 %3 %4")
.arg(m_curRecording->GetTitle()).arg(m_curRecording->GetChanID())
.arg(m_curRecording->GetRecordingStartTime(MythDate::ISODate))
.arg(m_curRecording->GetRecordingEndTime(MythDate::ISODate));
Expand Down Expand Up @@ -615,7 +614,7 @@ RecStatus::Type TVRec::StartRecording(ProgramInfo *pginfo)
}
else if (!did_switch)
{
msg = QString("Wanted to record: %1 %2 %3 %4\n\t\t\t")
QString msg = QString("Wanted to record: %1 %2 %3 %4\n\t\t\t")
.arg(rcinfo->GetTitle()).arg(rcinfo->GetChanID())
.arg(rcinfo->GetRecordingStartTime(MythDate::ISODate))
.arg(rcinfo->GetRecordingEndTime(MythDate::ISODate));
Expand Down
10 changes: 4 additions & 6 deletions mythtv/libs/libmythtv/visualisations/goom/drawmethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ static void draw_line (int *data, int x1, int y1, int x2, int y2, int col, int s
int y = 0;
int dx = 0;
int dy = 0;
int yy = 0;
int xx = 0;
int *p = nullptr;


Expand Down Expand Up @@ -113,7 +111,7 @@ static void draw_line (int *data, int x1, int y1, int x2, int y2, int col, int s
dx = ((dx << 16) / dy);
x = x1 << 16;
for (y = y1; y <= y2; y++) {
xx = x >> 16;
int xx = x >> 16;
p = &(data[(screenx * y) + xx]);
DRAWMETHOD;
if (xx < (screenx - 1)) {
Expand All @@ -127,7 +125,7 @@ static void draw_line (int *data, int x1, int y1, int x2, int y2, int col, int s
dy = ((dy << 16) / dx);
y = y1 << 16;
for (x = x1; x <= x2; x++) {
yy = y >> 16;
int yy = y >> 16;
p = &(data[(screenx * yy) + x]);
DRAWMETHOD;
y += dy;
Expand All @@ -142,7 +140,7 @@ static void draw_line (int *data, int x1, int y1, int x2, int y2, int col, int s
dx = ((dx << 16) / -dy);
x = (x1 + 1) << 16;
for (y = y1; y >= y2; y--) {
xx = x >> 16;
int xx = x >> 16;
p = &(data[(screenx * y) + xx]);
DRAWMETHOD;
if (xx < (screenx - 1)) {
Expand All @@ -156,7 +154,7 @@ static void draw_line (int *data, int x1, int y1, int x2, int y2, int col, int s
dy = ((dy << 16) / dx);
y = y1 << 16;
for (x = x1; x <= x2; x++) {
yy = y >> 16;
int yy = y >> 16;
p = &(data[(screenx * yy) + x]);
DRAWMETHOD;
y += dy;
Expand Down
Loading

0 comments on commit 698c347

Please sign in to comment.