Skip to content

Commit

Permalink
Remove penultimate call to xstrdup in project from mtk. (#1406)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Lipe <[email protected]>
  • Loading branch information
robertlipe and Robert Lipe authored Jan 27, 2025
1 parent ca990a1 commit 27c1f7c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
30 changes: 15 additions & 15 deletions mtk_logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#include "gbfile.h" // for gbfprintf, gbfputc, gbfputs, gbfclose, gbfopen, gbfile
#include "gbser.h" // for gbser_read_line, gbser_set_port, gbser_OK, gbser_deinit, gbser_init, gbser_print, gbser_TIMEOUT
#include "src/core/datetime.h" // for DateTime
#include "src/core/logging.h" // for Fatal, Warning


#define MTK_EVT_BITMASK (1<<0x02)
Expand All @@ -97,7 +98,7 @@

#define HOLUX245_MASK (1 << 27)


// TODO: These should become Debug() from src/core/logging.
void MtkLoggerBase::dbg(int l, const char* msg, ...)
{
if (global_opts.debug_level >= l) {
Expand Down Expand Up @@ -244,12 +245,12 @@ void MtkLoggerBase::mtk_rd_init(const QString& fname)
int rc;
char* model;

port = xstrdup(qPrintable(fname));
port = fname;

errno = 0;
dbg(1, "Opening port %s...\n", port);
if ((fd = gbser_init(port)) == nullptr) {
gbFatal("Can't initialise port \"%s\" (%s)\n", port, strerror(errno));
dbg(1, "Opening port %s...\n", qPrintable(port));
if ((fd = gbser_init(qPrintable(port))) == nullptr) {
gbFatal(FatalMsg() << "Can't initialise port" << port << strerror(errno));
}

// verify that we have a MTK based logger...
Expand Down Expand Up @@ -301,7 +302,7 @@ void MtkLoggerBase::mtk_rd_deinit()
dbg(3, "Closing port...\n");
gbser_deinit(fd);
fd = nullptr;
xfree(port);
port = nullptr;
}

int MtkLoggerBase::mtk_erase()
Expand Down Expand Up @@ -363,8 +364,7 @@ void MtkLoggerBase::mtk_read()
if (dout == nullptr) {
dout = ufopen(TEMP_DATA_BIN, "wb");
if (dout == nullptr) {
gbFatal("Can't create temporary file %s\n",
gbLogCStr(TEMP_DATA_BIN));
gbFatal(FatalMsg() << "Can't create temporary file" << TEMP_DATA_BIN);
}
}
fseek(dout, 0L,SEEK_END);
Expand All @@ -375,7 +375,7 @@ void MtkLoggerBase::mtk_read()
dpos = 0;
init_scan = 1;
}
dbg(1, "Download %s -> %s\n", port, gbLogCStr(TEMP_DATA_BIN));
dbg(1, "Download %s -> %s\n", qPrintable(port), gbLogCStr(TEMP_DATA_BIN));

// check log status - is logging disabled ?
do_cmd(CMD_LOG_STATUS, "PMTK182,3,7,", &fusage, 2);
Expand Down Expand Up @@ -418,8 +418,7 @@ void MtkLoggerBase::mtk_read()
QFile::rename(TEMP_DATA_BIN, TEMP_DATA_BIN_OLD);
dout = ufopen(TEMP_DATA_BIN, "wb");
if (dout == nullptr) {
gbFatal("Can't create temporary file %s\n",
gbLogCStr(TEMP_DATA_BIN));
gbFatal(FatalMsg() << "Can't create temporary file " << TEMP_DATA_BIN);
}
}

Expand Down Expand Up @@ -735,12 +734,13 @@ void MtkLoggerBase::mtk_csv_init(const QString& csv_fname, unsigned long bitmask
// can't use gbfopen here - it will gbFatal() if file doesn't exist
if ((cf = ufopen(csv_fname, "r")) != nullptr) {
fclose(cf);
gbWarning("CSV file %s already exist ! Cowardly refusing to overwrite.\n", gbLogCStr(csv_fname));
Warning() << "CSV file " << gbLogCStr(csv_fname) <<
"already exists ! Cowardly refusing to overwrite";
return;
}

if ((cd = gbfopen(csv_fname, "w")) == nullptr) {
gbFatal("Can't open csv file '%s'\n", gbLogCStr(csv_fname));
gbFatal(FatalMsg() << "Can't open csv file " << csv_fname);
}

/* Add the header line */
Expand Down Expand Up @@ -1263,7 +1263,7 @@ void MtkLoggerBase::file_init(const QString& fname)
{
dbg(4, "Opening file %s...\n", gbLogCStr(fname));
if (fl = ufopen(fname, "rb"), nullptr == fl) {
gbFatal("Can't open file '%s'\n", gbLogCStr(fname));
gbFatal(FatalMsg() << "Can't open file" << fname);
}
switch (mtk_device) {
case HOLUX_M241:
Expand Down Expand Up @@ -1319,7 +1319,7 @@ void MtkLoggerBase::file_read()
fseek(fl, 0L, SEEK_END);
long fsize = ftell(fl);
if (fsize <= 0) {
gbFatal("File has size %ld\n", fsize);
gbFatal(FatalMsg() << "File has size" << fsize);
}

fseek(fl, 0L, SEEK_SET);
Expand Down
2 changes: 1 addition & 1 deletion mtk_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class MtkLoggerBase

void* fd{}; /* serial fd */
FILE* fl{}; /* bin.file fd */
char* port{}; /* serial port name */
QString port{}; /* serial port name */
OptionBool OPT_erase; /* erase ? command option */
OptionBool OPT_erase_only; /* erase_only ? command option */
OptionBool OPT_log_enable; /* enable ? command option */
Expand Down

0 comments on commit 27c1f7c

Please sign in to comment.