Skip to content

Commit

Permalink
fix: improved safety
Browse files Browse the repository at this point in the history
  • Loading branch information
kg68k committed Nov 26, 2024
1 parent 3b01110 commit 9abd6af
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
13 changes: 8 additions & 5 deletions src/generate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ソースコードジェネレートモジュール
// Copyright (C) 1989,1990 K.Abe, 1994 R.ShimiZu
// All rights reserved.
// Copyright (C) 1997-2023 TcbnErik
// Copyright (C) 2024 TcbnErik

#include "generate.h"

Expand Down Expand Up @@ -204,9 +204,11 @@ lblbuf* generateSection(char* sfilename, char* section, address end,
} else if (isTABLE(mode)) {
pc = tablegen(pc, type);
if (pc != nextLabel->label) {
// テーブル終了条件を end[num]、end[breakonly] にするとラベルを越えてテーブルとして認識され、
// tablegen() でまるごと出力されるので、その場合は pc もテーブル終端まで進める
// テーブル終了条件を end[num]、end[breakonly] にするとラベルを越えて
// テーブルとして認識され、tablegen() でまるごと出力されるので、
// その場合は pc もテーブル終端まで進める
nextLabel = search_label(pc);
if (!nextLabel) break;
}
} else if (isBSS) {
bssgen(pc, nextLabel->label, lblmodeOpesize(mode));
Expand Down Expand Up @@ -1463,8 +1465,9 @@ static char* operandToLabel(char* p, operand* op) {
// アウターディスプレースメント
if (op->exod == 4 && INPROG(op->opval2, op->eaadrs2)) {
makeSymLabFormula(&slfml, op->opval2);
while (*(--p) != ',')
;
while (*(--p) != ',') {
// loop
}
p += 1;
p = catSlfml(p, &slfml);
*p++ = ')';
Expand Down
4 changes: 2 additions & 2 deletions src/include.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ static int getlabel(const IncludeSpec* spec, char* linebuf) {

// マクロ名: .macro 実引数名
if (strcasecmp(psdptr, "macro") == 0) {
if ((strlen(symptr) < MAX_MACRO_LEN) && spec->macroPtr) {
strcpy(spec->macroPtr, symptr);
if (spec->macroPtr && (strlen(symptr) < MAX_MACRO_LEN)) {
strncpy(spec->macroPtr, symptr, MAX_MACRO_LEN);
}
}
return 0;
Expand Down
5 changes: 3 additions & 2 deletions src/label.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ラベル管理モジュール
// Copyright (C) 1989,1990 K.Abe
// All rights reserved.
// Copyright (C) 1997-2023 TcbnErik
// Copyright (C) 2024 TcbnErik

#include "label.h"

Expand Down Expand Up @@ -50,9 +50,10 @@ boolean registerLabelDebug(address adrs, lblmode mode, address target,
if (adrs == target) {
const char* b = result ? "TRUE" : "FALSE";
lblbuf* lptr = search_label(adrs);
unsigned int mode = lptr ? (unsigned int)lptr->mode : 0;
eprintf("\n%s:%d: registerLabel(adrs=" PRI_ADRS
", mode=$%06x) -> %s (mode=$%06x). ",
file, line, adrs, (unsigned int)mode, b, (unsigned int)lptr->mode);
file, line, adrs, (unsigned int)mode, b, mode);
}

return result;
Expand Down

0 comments on commit 9abd6af

Please sign in to comment.