Skip to content

Commit

Permalink
Some code quality issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hozuki committed Apr 15, 2020
1 parent b64052f commit 2b717b3
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 28 deletions.
7 changes: 5 additions & 2 deletions src/apps/acb2hcas/acb2hcas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cinttypes>

#include "../../lib/cgss_api.h"
#include "../common/common.h"
Expand Down Expand Up @@ -182,14 +183,16 @@ ProcessAllBinaries(CAcbFile *acb, uint32_t formatVersion, const Acb2HcasOptions
keyModifier = 0;
}

for (auto &entry : archive->GetFiles()) {
const auto &fileList = archive->GetFiles();

for (auto &entry : fileList) {
auto &record = entry.second;

auto fileData = CAcbHelper::ExtractToNewStream(dataStream, record.fileOffsetAligned, (uint32_t)record.fileSize);

const auto isHca = CHcaFormatReader::IsPossibleHcaStream(fileData);

fprintf(stdout, "Processing %s AFS: #%u (offset=%u, size=%u)",
fprintf(stdout, "Processing %s AFS: #%" PRIu32 " (offset=%" PRIu32 ", size=%" PRIu32 ")",
afsSource, (uint32_t)record.cueId, (uint32_t)record.fileOffsetAligned, (uint32_t)record.fileSize);

if (isHca) {
Expand Down
3 changes: 2 additions & 1 deletion src/apps/acb2wavs/acb2wavs.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <iostream>
#include <string>
#include <algorithm>
#include <cinttypes>

#include "../cgssh.h"
#include "../../lib/cgss_api.h"
Expand Down Expand Up @@ -179,7 +180,7 @@ ProcessAllBinaries(CAcbFile *acb, uint32_t formatVersion, const Acb2WavsOptions

const auto isHca = CHcaFormatReader::IsPossibleHcaStream(fileData);

fprintf(stdout, "Processing %s AFS: #%u (offset=%u, size=%u)",
fprintf(stdout, "Processing %s AFS: #%" PRIu32 " (offset=%" PRIu32 ", size=%" PRIu32 ")",
afsSource, (uint32_t)record.cueId, (uint32_t)record.fileOffsetAligned, (uint32_t)record.fileSize);

int r;
Expand Down
9 changes: 5 additions & 4 deletions src/apps/acbunpack/acbunpack.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <cstdio>
#include <cstdint>
#include <cstring>
#include <cinttypes>

#if defined(_WIN32) || defined(WIN32)

Expand Down Expand Up @@ -76,7 +77,7 @@ int main(int argc, const char *argv[]) {

common_utils::CopyStream(stream, &fs);
} else {
fprintf(stderr, "Cue #%u (%s) cannot be retrieved.\n", i + 1, s.c_str());
fprintf(stderr, "Cue #%" PRIu32 " (%s) cannot be retrieved.\n", i + 1, s.c_str());
}

delete stream;
Expand Down
8 changes: 4 additions & 4 deletions src/apps/utftable/utftable.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ static void print_table_recursive(UTF_TABLE *table, uint32_t indent) {
indent += INDENT_VALUE;

PRINT_INDENT();
printf("@%s (encrypted: %s, field count: %u, row count: %u)\n", table->tableName,
printf("@%s (encrypted: %s, field count: %" PRIu32 ", row count: %" PRIu32 ")\n", table->tableName,
BOOL_STR(table->isEncrypted), table->header.fieldCount, table->header.rowCount);

for (uint32_t i = 0; i < table->header.rowCount; ++i) {
UTF_ROW *currentRow = table->rows + i;

PRINT_INDENT();
printf("@%s [%u] = {\n", table->tableName, i);
printf("@%s [%" PRIu32 "] = {\n", table->tableName, i);
indent += INDENT_VALUE;

if (table->header.fieldCount == 0) {
Expand Down Expand Up @@ -139,7 +139,7 @@ static void print_table_recursive(UTF_TABLE *table, uint32_t indent) {
}

PRINT_INDENT();
printf("%08x (row+%08x) %2x %s [%s] =", currentField->offset, currentField->offsetInRow,
printf("%08" PRIx32 " (row+%08" PRIx32 ") %2x %s [%s] =", currentField->offset, currentField->offsetInRow,
(currentField->storage | currentField->type), currentField->name, columnTypeName);

const char *constantTypeStr;
Expand Down Expand Up @@ -201,7 +201,7 @@ static void print_table_recursive(UTF_TABLE *table, uint32_t indent) {

cgssUtfFreeTable(tbl);
} else {
printf("%s (size %u = 0x%x)", constantTypeStr, currentField->value.data.size, currentField->value.data.size);
printf("%s (size %" PRIu32 " = 0x%" PRIx32 ")", constantTypeStr, currentField->value.data.size, currentField->value.data.size);
}
break;
default:
Expand Down
10 changes: 6 additions & 4 deletions src/lib/capi/CHandleManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <cinttypes>

#include "CHandleManager.h"
#include "../takamori/exceptions/CArgumentException.h"

CGSS_NS_BEGIN

CHandleManager *CHandleManager::_instance = new CHandleManager();

CHandleManager::CHandleManager() {
CHandleManager::CHandleManager() noexcept {
HandleRecord record = {};
record.ptr = nullptr;
record.type = HandleType::None;
Expand All @@ -28,7 +30,7 @@ CGSS_NS_BEGIN
const auto iter = _handles.find(handle);
if (iter == _handles.cend()) {
char buffer[100] = {0};
sprintf(buffer, "Handle %u is invalid.", handle);
sprintf(buffer, "Handle %" PRIu32 " is invalid.", handle);
throw CArgumentException(buffer);
}
return iter->second.type;
Expand All @@ -38,7 +40,7 @@ CGSS_NS_BEGIN
const auto iter = _handles.find(handle);
if (iter == _handles.cend()) {
char buffer[100] = {0};
sprintf(buffer, "Handle %u is invalid.", handle);
sprintf(buffer, "Handle %" PRIu32 " is invalid.", handle);
throw CArgumentException(buffer);
}
return iter->second.ptr;
Expand Down Expand Up @@ -69,7 +71,7 @@ CGSS_NS_BEGIN
const auto iter = _handles.find(handle);
if (iter == _handles.cend()) {
char buffer[100] = {0};
sprintf(buffer, "Handle %u is invalid.", handle);
sprintf(buffer, "Handle %" PRIu32 " is invalid.", handle);
throw CArgumentException(buffer);
}
if (dispose) {
Expand Down
12 changes: 9 additions & 3 deletions src/lib/capi/CHandleManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ CGSS_NS_BEGIN
CHcaReaderBase = 0x03
};

CHandleManager(const CHandleManager &) = delete;

CHandleManager(CHandleManager &&) = delete;

CHandleManager &operator=(const CHandleManager &) = delete;

CHandleManager &operator=(CHandleManager &&) = delete;

uint32_t alloc(IStream *p, HandleType type);

void free(uint32_t handle, bool_t dispose = TRUE);
Expand All @@ -30,12 +38,10 @@ CGSS_NS_BEGIN

private:

CHandleManager();
CHandleManager() noexcept;

~CHandleManager();

CHandleManager(CHandleManager &) = delete;

static CHandleManager *_instance;

struct HandleRecord {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/ichinose/CAcbFile.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <string>
#include <cinttypes>

#include "../cgss_cenum.h"
#include "CAfs2Archive.h"
#include "../cgss_cdata.h"
Expand Down Expand Up @@ -269,7 +271,7 @@ IStream *CAcbFile::OpenDataStream(const char *fileName) {
IStream *CAcbFile::OpenDataStream(uint32_t cueId) {
char tempFileName[40] = {0};

sprintf(tempFileName, "cue #%u", cueId);
sprintf(tempFileName, "cue #%" PRIu32, cueId);

IStream *result = nullptr;

Expand Down
6 changes: 4 additions & 2 deletions src/lib/kawashima/hca/CHcaCipherConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <string>
#include <algorithm>
#include <cinttypes>

#include "CHcaCipherConverter.h"
#include "../../common/quick_utils.h"
#include "internal/CHcaCipher.h"
Expand Down Expand Up @@ -150,7 +152,7 @@ CGSS_NS_BEGIN

if (ComputeChecksum(blockBuffer, hcaInfo.blockSize, 0) != 0) {
char numberBuffer[20] = {0};
sprintf(numberBuffer, "%u", blockIndex);
sprintf(numberBuffer, "%" PRIu32, blockIndex);
throw CFormatException(std::string("CHcaCipherConverter::ConvertBlock @ Block#") + numberBuffer);
}

Expand All @@ -163,7 +165,7 @@ CGSS_NS_BEGIN
const auto magic = data.GetBit(16);
if (magic != 0xffff) {
char numberBuffer[20] = {0};
sprintf(numberBuffer, "%u", blockIndex);
sprintf(numberBuffer, "%" PRIu32, blockIndex);
throw CFormatException(std::string("CHcaCipherConverter::ConvertBlock @ Block#") + numberBuffer);
}

Expand Down
6 changes: 1 addition & 5 deletions src/lib/takamori/exceptions/CException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ CGSS_NS_BEGIN
: MyClass(std::string(message)) {
}

CException::CException(const cgss::CException &exception) noexcept
: MyBase(), _result(exception._result), _message(exception._message) {
}

CException::CException(const std::string &message) noexcept
: MyClass(CGSS_OP_GENERIC_FAULT, message) {
}
Expand All @@ -33,7 +29,7 @@ CGSS_NS_BEGIN
return *this;
}

const std::string CException::GetExceptionMessage() const noexcept {
const std::string &CException::GetExceptionMessage() const noexcept {
return _message;
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/takamori/exceptions/CException.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ CGSS_NS_BEGIN

CException() noexcept;

CException(const CException &) noexcept;
CException(const CException &) noexcept = default;

CException& operator=(const CException &) noexcept;

Expand All @@ -28,7 +28,7 @@ CGSS_NS_BEGIN

virtual ~CException() noexcept = default;

virtual const std::string GetExceptionMessage() const noexcept;
virtual const std::string &GetExceptionMessage() const noexcept;

virtual CGSS_OP_RESULT GetOpResult() const noexcept;

Expand Down

0 comments on commit 2b717b3

Please sign in to comment.