Skip to content

Commit fb54467

Browse files
committed
Fixed warning related to nullptr and conversions
1 parent e953f7d commit fb54467

11 files changed

+85
-72
lines changed

qt/buffer_table_model.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ QVariant BufferTableModel::data(const QModelIndex &index, int role) const
3535
case HEADER_ADDRESS_COL:
3636
return QString("%1").arg(index.row() * ROW_DATA_SIZE, 8, 16,
3737
QChar('0'));
38-
break;
3938
case HEADER_HEX_COL:
40-
start = index.row() * ROW_DATA_SIZE;
39+
start = static_cast<uint32_t>(index.row()) * ROW_DATA_SIZE;
4140
end = start + ROW_DATA_SIZE;
4241

4342
for (uint32_t i = start; i < end && i < bufSize; i++)
@@ -47,7 +46,7 @@ QVariant BufferTableModel::data(const QModelIndex &index, int role) const
4746
}
4847
return hexString;
4948
case HEADER_ANCII_COL:
50-
start = index.row() * ROW_DATA_SIZE;
49+
start = static_cast<uint32_t>(index.row()) * ROW_DATA_SIZE;
5150
end = start + ROW_DATA_SIZE;
5251

5352
for (uint32_t i = start; i < end && i < bufSize; i++)

qt/buffer_table_model.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class BufferTableModel: public QAbstractTableModel
2222
uint32_t bufSize;
2323

2424
public:
25-
BufferTableModel(QObject *parent = 0);
25+
BufferTableModel(QObject *parent = nullptr);
2626
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
2727
int columnCount(const QModelIndex &parent = QModelIndex()) const
2828
override;

qt/chip_db.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class ChipDb : public QObject
6363
void writeToCvs();
6464

6565
public:
66-
explicit ChipDb(QObject *parent = 0);
66+
explicit ChipDb(QObject *parent = nullptr);
6767
QStringList getNames();
6868
ChipInfo *chipInfoGetById(int id);
6969
uint32_t pageSizeGetById(int id);

qt/logger.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Logger::Logger()
6464

6565
Logger::~Logger()
6666
{
67-
qInstallMessageHandler(0);
67+
qInstallMessageHandler(nullptr);
6868
}
6969

7070
Logger *Logger::getInstance()
@@ -87,8 +87,8 @@ void Logger::putInstance()
8787
if (!--refCount && logger)
8888
{
8989
delete logger;
90-
logger = 0;
91-
logTextEdit = 0;
90+
logger = nullptr;
91+
logTextEdit = nullptr;
9292
}
9393
}
9494

qt/main_window.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class MainWindow : public QMainWindow
2121

2222
Programmer *prog;
2323
public:
24-
explicit MainWindow(QWidget *parent = 0);
24+
explicit MainWindow(QWidget *parent = nullptr);
2525
~MainWindow();
2626

2727
private:

qt/programmer.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,11 @@ void Programmer::readChipId(ChipId *chipId)
115115
/* Serial port object cannot be used in other thread */
116116
serialPortDisconnect();
117117
writeData.clear();
118-
writeData.append((const char *)&cmd, sizeof(cmd));
119-
reader.init(usbDevName, SERIAL_PORT_SPEED, (uint8_t *)chipId,
120-
sizeof(ChipId), (uint8_t *)writeData.constData(), writeData.size(),
121-
false, false);
118+
writeData.append(reinterpret_cast<const char *>(&cmd), sizeof(cmd));
119+
reader.init(usbDevName, SERIAL_PORT_SPEED,
120+
reinterpret_cast<uint8_t *>(chipId), sizeof(ChipId),
121+
reinterpret_cast<const uint8_t *>(writeData.constData()),
122+
static_cast<uint32_t>(writeData.size()), false, false);
122123
reader.start();
123124
}
124125

@@ -142,9 +143,11 @@ void Programmer::eraseChip(uint32_t addr, uint32_t len)
142143
/* Serial port object cannot be used in other thread */
143144
serialPortDisconnect();
144145
writeData.clear();
145-
writeData.append((const char *)&eraseCmd, sizeof(eraseCmd));
146-
reader.init(usbDevName, SERIAL_PORT_SPEED, NULL, 0,
147-
(uint8_t *)writeData.constData(), writeData.size(), skipBB, false);
146+
writeData.append(reinterpret_cast<const char *>(&eraseCmd),
147+
sizeof(eraseCmd));
148+
reader.init(usbDevName, SERIAL_PORT_SPEED, nullptr, 0,
149+
reinterpret_cast<const uint8_t *>(writeData.constData()),
150+
static_cast<uint32_t>(writeData.size()), skipBB, false);
148151
reader.start();
149152
}
150153

@@ -167,9 +170,10 @@ void Programmer::readChip(uint8_t *buf, uint32_t addr, uint32_t len,
167170
/* Serial port object cannot be used in other thread */
168171
serialPortDisconnect();
169172
writeData.clear();
170-
writeData.append((const char *)&readCmd, sizeof(readCmd));
173+
writeData.append(reinterpret_cast<const char *>(&readCmd), sizeof(readCmd));
171174
reader.init(usbDevName, SERIAL_PORT_SPEED, buf, len,
172-
(uint8_t *)writeData.constData(), writeData.size(), skipBB,
175+
reinterpret_cast<const uint8_t *>(writeData.constData()),
176+
static_cast<uint32_t>(writeData.size()), skipBB,
173177
isReadLess);
174178
reader.start();
175179
}
@@ -211,9 +215,10 @@ void Programmer::readChipBadBlocks()
211215
/* Serial port object cannot be used in other thread */
212216
serialPortDisconnect();
213217
writeData.clear();
214-
writeData.append((const char *)&cmd, sizeof(cmd));
215-
reader.init(usbDevName, SERIAL_PORT_SPEED, NULL, 0,
216-
(uint8_t *)writeData.constData(), writeData.size(), false, false);
218+
writeData.append(reinterpret_cast<const char *>(&cmd), sizeof(cmd));
219+
reader.init(usbDevName, SERIAL_PORT_SPEED, nullptr, 0,
220+
reinterpret_cast<const uint8_t *>(writeData.constData()),
221+
static_cast<uint32_t>(writeData.size()), false, false);
217222
reader.start();
218223
}
219224

@@ -250,9 +255,10 @@ void Programmer::confChip(ChipInfo *chipInfo)
250255
/* Serial port object cannot be used in other thread */
251256
serialPortDisconnect();
252257
writeData.clear();
253-
writeData.append((const char *)&confCmd, sizeof(confCmd));
254-
reader.init(usbDevName, SERIAL_PORT_SPEED, NULL, 0,
255-
(uint8_t *)writeData.constData(), writeData.size(), false, false);
258+
writeData.append(reinterpret_cast<const char *>(&confCmd), sizeof(confCmd));
259+
reader.init(usbDevName, SERIAL_PORT_SPEED, nullptr, 0,
260+
reinterpret_cast<const uint8_t *>(writeData.constData()),
261+
static_cast<uint32_t>(writeData.size()), false, false);
256262
reader.start();
257263
}
258264

qt/programmer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Programmer : public QObject
3434
public:
3535
QByteArray writeData;
3636

37-
explicit Programmer(QObject *parent = 0);
37+
explicit Programmer(QObject *parent = nullptr);
3838
~Programmer();
3939
int connect();
4040
void disconnect();

qt/reader.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
Q_DECLARE_METATYPE(QtMsgType)
1717

1818
void Reader::init(const QString &portName, qint32 baudRate, uint8_t *rbuf,
19-
uint32_t rlen, uint8_t *wbuf, uint32_t wlen, bool isSkipBB, bool isReadLess)
19+
uint32_t rlen, const uint8_t *wbuf, uint32_t wlen, bool isSkipBB,
20+
bool isReadLess)
2021
{
2122
this->portName = portName;
2223
this->baudRate = baudRate;
@@ -30,17 +31,17 @@ void Reader::init(const QString &portName, qint32 baudRate, uint8_t *rbuf,
3031
bytesRead = 0;
3132
}
3233

33-
int Reader::write(uint8_t *data, uint32_t len)
34+
int Reader::write(const uint8_t *data, uint32_t len)
3435
{
35-
int ret;
36+
qint64 ret;
3637

37-
ret = serialPort->write((char *)data, len);
38+
ret = serialPort->write(reinterpret_cast<const char *>(data), len);
3839
if (ret < 0)
3940
{
4041
logErr(QString("Failed to write: %1").arg(serialPort->errorString()));
4142
return -1;
4243
}
43-
else if ((uint32_t)ret < len)
44+
else if (ret < len)
4445
{
4546
logErr(QString("Data was partialy written, returned %1, expected %2")
4647
.arg(ret).arg(len));
@@ -57,27 +58,27 @@ int Reader::readStart()
5758

5859
int Reader::read(uint8_t *pbuf, uint32_t len)
5960
{
60-
int ret;
61+
qint64 ret;
6162

6263
if (!serialPort->waitForReadyRead(READ_TIMEOUT))
6364
{
6465
logErr("Read data timeout");
6566
return -1;
6667
}
6768

68-
ret = serialPort->read((char *)pbuf, len);
69+
ret = serialPort->read(reinterpret_cast<char *>(pbuf), len);
6970
if (ret < 0)
7071
{
7172
logErr("Failed to read data");
7273
return -1;
7374
}
7475

75-
return ret;
76+
return static_cast<int>(ret);
7677
}
7778

7879
int Reader::handleBadBlock(uint8_t *pbuf, uint32_t len, bool isSkipped)
7980
{
80-
RespBadBlock *badBlock = (RespBadBlock *)pbuf;
81+
RespBadBlock *badBlock = reinterpret_cast<RespBadBlock *>(pbuf);
8182
size_t size = sizeof(RespBadBlock);
8283
QString message = isSkipped ? "Skipped bad block at 0x%1 size 0x%2" :
8384
"Bad block at 0x%1 size 0x%2";
@@ -96,12 +97,12 @@ int Reader::handleBadBlock(uint8_t *pbuf, uint32_t len, bool isSkipped)
9697
bytesRead += badBlock->size;
9798
}
9899

99-
return size;
100+
return static_cast<int>(size);
100101
}
101102

102103
int Reader::handleError(uint8_t *pbuf, uint32_t len)
103104
{
104-
RespError *err = (RespError *)pbuf;
105+
RespError *err = reinterpret_cast<RespError *>(pbuf);
105106
size_t size = sizeof(RespError);
106107

107108
if (len < size)
@@ -115,7 +116,7 @@ int Reader::handleError(uint8_t *pbuf, uint32_t len)
115116

116117
int Reader::handleStatus(uint8_t *pbuf, uint32_t len)
117118
{
118-
RespHeader *header = (RespHeader *)pbuf;
119+
RespHeader *header = reinterpret_cast<RespHeader *>(pbuf);
119120

120121
switch (header->info)
121122
{
@@ -140,7 +141,7 @@ int Reader::handleStatus(uint8_t *pbuf, uint32_t len)
140141

141142
int Reader::handleData(uint8_t *pbuf, uint32_t len)
142143
{
143-
RespHeader *header = (RespHeader *)pbuf;
144+
RespHeader *header = reinterpret_cast<RespHeader *>(pbuf);
144145
uint8_t dataSize = header->info;
145146
size_t headerSize = sizeof(RespHeader), packetSize = headerSize + dataSize;
146147

@@ -164,12 +165,12 @@ int Reader::handleData(uint8_t *pbuf, uint32_t len)
164165
readOffset += dataSize;
165166
bytesRead += dataSize;
166167

167-
return packetSize;
168+
return static_cast<int>(packetSize);
168169
}
169170

170171
int Reader::handlePacket(uint8_t *pbuf, uint32_t len)
171172
{
172-
RespHeader *header = (RespHeader *)pbuf;
173+
RespHeader *header = reinterpret_cast<RespHeader *>(pbuf);
173174

174175
if (len < sizeof(RespHeader))
175176
return 0;
@@ -185,8 +186,6 @@ int Reader::handlePacket(uint8_t *pbuf, uint32_t len)
185186
.arg(header->code));
186187
return -1;
187188
}
188-
189-
return 0;
190189
}
191190

192191
int Reader::handlePackets(uint8_t *pbuf, uint32_t len)
@@ -199,7 +198,7 @@ int Reader::handlePackets(uint8_t *pbuf, uint32_t len)
199198
return -1;
200199

201200
if (ret)
202-
offset += ret;
201+
offset += static_cast<uint32_t>(ret);
203202
else
204203
{
205204
memmove(pbuf, pbuf + offset, len - offset);
@@ -208,7 +207,7 @@ int Reader::handlePackets(uint8_t *pbuf, uint32_t len)
208207
}
209208
while (offset < len);
210209

211-
return len - offset;
210+
return static_cast<int>(len - offset);
212211
}
213212

214213
int Reader::readData()
@@ -218,11 +217,14 @@ int Reader::readData()
218217

219218
do
220219
{
221-
if ((len = read(pbuf + offset, BUF_SIZE - offset)) < 0)
220+
if ((len = read(pbuf + offset,
221+
BUF_SIZE - static_cast<uint32_t>(offset))) < 0)
222+
{
222223
return -1;
224+
}
223225
len += offset;
224226

225-
if ((offset = handlePackets(pbuf, len)) < 0)
227+
if ((offset = handlePackets(pbuf, static_cast<uint32_t>(len))) < 0)
226228
return -1;
227229

228230
if (!bytesRead)

qt/reader.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Reader : public QThread
1818
qint32 baudRate;
1919
uint8_t *rbuf;
2020
uint32_t rlen;
21-
uint8_t *wbuf;
21+
const uint8_t *wbuf;
2222
uint32_t wlen;
2323
uint32_t readOffset;
2424
uint32_t bytesRead;
@@ -27,7 +27,7 @@ class Reader : public QThread
2727

2828
int serialPortCreate();
2929
void serialPortDestroy();
30-
int write(uint8_t *data, uint32_t len);
30+
int write(const uint8_t *data, uint32_t len);
3131
int readStart();
3232
int read(uint8_t *pbuf, uint32_t len);
3333
int handleError(uint8_t *pbuf, uint32_t len);
@@ -43,7 +43,7 @@ class Reader : public QThread
4343

4444
public:
4545
void init(const QString &portName, qint32 baudRate, uint8_t *rbuf,
46-
uint32_t rlen, uint8_t *wbuf, uint32_t wlen, bool isSkipBB,
46+
uint32_t rlen, const uint8_t *wbuf, uint32_t wlen, bool isSkipBB,
4747
bool isReadLess);
4848
signals:
4949
void result(int ret);

qt/settings_programmer_dialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class SettingsProgrammerDialog : public QDialog
1212
Q_OBJECT
1313

1414
public:
15-
explicit SettingsProgrammerDialog(QWidget *parent = 0);
15+
explicit SettingsProgrammerDialog(QWidget *parent = nullptr);
1616
~SettingsProgrammerDialog();
1717
void setUsbDevName(const QString &name);
1818
QString getUsbDevName();

0 commit comments

Comments
 (0)