mirror of
https://gitlab.com/Theopse/fbi-i18n-zh.git
synced 2026-01-02 10:26:56 +08:00
Correct use of string_copy when building strings.
This commit is contained in:
parent
62e9632a43
commit
6a4a446df0
@ -22,8 +22,10 @@ bool string_is_empty(const char* str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void string_copy(char* dst, const char* src, size_t size) {
|
void string_copy(char* dst, const char* src, size_t size) {
|
||||||
strncpy(dst, src, size - 1);
|
if(size > 0) {
|
||||||
dst[size - 1] = '\0';
|
strncpy(dst, src, size - 1);
|
||||||
|
dst[size - 1] = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void string_get_file_name(char* out, const char* file, u32 size) {
|
void string_get_file_name(char* out, const char* file, u32 size) {
|
||||||
|
|||||||
@ -370,18 +370,18 @@ void action_install_url(const char* confirmMessage, const char* urls, const char
|
|||||||
u32 len = currEnd - currStart;
|
u32 len = currEnd - currStart;
|
||||||
|
|
||||||
if((len < 7 || strncmp(currStart, "http://", 7) != 0) && (len < 8 || strncmp(currStart, "https://", 8) != 0)) {
|
if((len < 7 || strncmp(currStart, "http://", 7) != 0) && (len < 8 || strncmp(currStart, "https://", 8) != 0)) {
|
||||||
if(len > DOWNLOAD_URL_MAX - 7) {
|
if(len > DOWNLOAD_URL_MAX - 8) {
|
||||||
len = DOWNLOAD_URL_MAX - 7;
|
len = DOWNLOAD_URL_MAX - 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(data->urls[data->installInfo.total], "http://", 8);
|
string_copy(data->urls[data->installInfo.total], "http://", 8);
|
||||||
strncpy(&data->urls[data->installInfo.total][7], currStart, len);
|
string_copy(&data->urls[data->installInfo.total][7], currStart, len + 1);
|
||||||
} else {
|
} else {
|
||||||
if(len > DOWNLOAD_URL_MAX) {
|
if(len > DOWNLOAD_URL_MAX - 1) {
|
||||||
len = DOWNLOAD_URL_MAX;
|
len = DOWNLOAD_URL_MAX - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(data->urls[data->installInfo.total], currStart, len);
|
string_copy(data->urls[data->installInfo.total], currStart, len + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
data->installInfo.total++;
|
data->installInfo.total++;
|
||||||
@ -400,11 +400,11 @@ void action_install_url(const char* confirmMessage, const char* urls, const char
|
|||||||
}
|
}
|
||||||
|
|
||||||
u32 len = currEnd - currStart;
|
u32 len = currEnd - currStart;
|
||||||
if(len > FILE_PATH_MAX) {
|
if(len > FILE_PATH_MAX - 1) {
|
||||||
len = FILE_PATH_MAX;
|
len = FILE_PATH_MAX - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(data->paths[i], currStart, len);
|
string_copy(data->paths[i], currStart, len + 1);
|
||||||
|
|
||||||
currStart = currEnd + 1;
|
currStart = currEnd + 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -92,7 +92,7 @@ static Result task_populate_titles_add_twl(populate_titles_data* data, FS_MediaT
|
|||||||
Result res = 0;
|
Result res = 0;
|
||||||
|
|
||||||
u64 realTitleId = 0;
|
u64 realTitleId = 0;
|
||||||
char productCode[12] = {'\0'};
|
char productCode[0x10] = {'\0'};
|
||||||
u16 version = 0;
|
u16 version = 0;
|
||||||
u64 installedSize = 0;
|
u64 installedSize = 0;
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ static Result task_populate_titles_add_twl(populate_titles_data* data, FS_MediaT
|
|||||||
installedSize = entry.size;
|
installedSize = entry.size;
|
||||||
} else if(R_SUCCEEDED(res = headerRes)) {
|
} else if(R_SUCCEEDED(res = headerRes)) {
|
||||||
memcpy(&realTitleId, &header[0x230], sizeof(realTitleId));
|
memcpy(&realTitleId, &header[0x230], sizeof(realTitleId));
|
||||||
memcpy(productCode, header, sizeof(productCode));
|
memcpy(productCode, header, 0xC);
|
||||||
version = header[0x01E];
|
version = header[0x01E];
|
||||||
|
|
||||||
u32 size = 0;
|
u32 size = 0;
|
||||||
@ -127,7 +127,7 @@ static Result task_populate_titles_add_twl(populate_titles_data* data, FS_MediaT
|
|||||||
if(titleInfo != NULL) {
|
if(titleInfo != NULL) {
|
||||||
titleInfo->mediaType = mediaType;
|
titleInfo->mediaType = mediaType;
|
||||||
titleInfo->titleId = realTitleId;
|
titleInfo->titleId = realTitleId;
|
||||||
string_copy(titleInfo->productCode, productCode, 12);
|
string_copy(titleInfo->productCode, productCode, sizeof(titleInfo->productCode));
|
||||||
titleInfo->version = version;
|
titleInfo->version = version;
|
||||||
titleInfo->installedSize = installedSize;
|
titleInfo->installedSize = installedSize;
|
||||||
titleInfo->twl = true;
|
titleInfo->twl = true;
|
||||||
@ -142,25 +142,31 @@ static Result task_populate_titles_add_twl(populate_titles_data* data, FS_MediaT
|
|||||||
utf16_to_utf8((uint8_t*) title, bnr_select_title(bnr), sizeof(title) - 1);
|
utf16_to_utf8((uint8_t*) title, bnr_select_title(bnr), sizeof(title) - 1);
|
||||||
|
|
||||||
if(strchr(title, '\n') == NULL) {
|
if(strchr(title, '\n') == NULL) {
|
||||||
size_t len = strlen(title);
|
string_copy(item->name, title, sizeof(item->name));
|
||||||
string_copy(item->name, title, len);
|
string_copy(titleInfo->meta.shortDescription, title, sizeof(titleInfo->meta.shortDescription));
|
||||||
string_copy(titleInfo->meta.shortDescription, title, len);
|
|
||||||
} else {
|
} else {
|
||||||
char* destinations[] = {titleInfo->meta.shortDescription, titleInfo->meta.longDescription, titleInfo->meta.publisher};
|
char* destinations[] = {titleInfo->meta.shortDescription, titleInfo->meta.longDescription, titleInfo->meta.publisher};
|
||||||
|
u32 destinationLens[] = {sizeof(titleInfo->meta.shortDescription), sizeof(titleInfo->meta.longDescription), sizeof(titleInfo->meta.publisher)};
|
||||||
int currDest = 0;
|
int currDest = 0;
|
||||||
|
|
||||||
char* last = title;
|
char* last = title;
|
||||||
char* curr = NULL;
|
char* curr = NULL;
|
||||||
|
|
||||||
while(currDest < 3 && (curr = strchr(last, '\n')) != NULL) {
|
while(currDest < 3 && (curr = strchr(last, '\n')) != NULL) {
|
||||||
string_copy(destinations[currDest++], last, curr - last);
|
u32 copyLen = curr - last + 1;
|
||||||
|
if(copyLen > destinationLens[currDest]) {
|
||||||
|
copyLen = destinationLens[currDest];
|
||||||
|
}
|
||||||
|
|
||||||
|
string_copy(destinations[currDest++], last, copyLen);
|
||||||
|
|
||||||
last = curr + 1;
|
last = curr + 1;
|
||||||
*curr = ' ';
|
*curr = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
string_copy(item->name, title, last - title);
|
string_copy(item->name, title, last - title);
|
||||||
if(currDest < 3) {
|
if(currDest < 3) {
|
||||||
string_copy(destinations[currDest], last, strlen(title) - (last - title));
|
string_copy(destinations[currDest], last, destinationLens[currDest]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user