From: sECuRE Date: Sun, 30 Nov 2008 11:09:09 +0000 (+0000) Subject: Store maximum item name's length in MAX_ITEM_NAME_LENGTH to increase it easily X-Git-Tag: rgb2rv6~22 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ccbd26c5061578d67e8656180452c3f19224cff5;p=c128-kasse Store maximum item name's length in MAX_ITEM_NAME_LENGTH to increase it easily git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@87 af93e077-1a23-4f1e-9cbe-9382a9d578f5 --- diff --git a/include/config.h b/include/config.h index 02513a4..18cbb11 100644 --- a/include/config.h +++ b/include/config.h @@ -4,6 +4,7 @@ #define CONFIG_H_ #define MAX_ITEMS 16 +#define MAX_ITEM_NAME_LENGTH 9 #define MAX_CREDIT_ITEMS 75 /* Eingenommes Geld in Cent */ @@ -14,7 +15,7 @@ extern BYTE printer_port; /* Datenstruktur der verkauften Einträge */ struct status_t { - char item_name[10]; + char item_name[MAX_ITEM_NAME_LENGTH+1]; /* Wieviel kostet der Eintrag (in Cent)? */ unsigned int price; /* Wie oft wurde er verkauft */ diff --git a/src/itemz.c b/src/itemz.c index 76d8022..7e72f57 100644 --- a/src/itemz.c +++ b/src/itemz.c @@ -41,7 +41,7 @@ static void new_item() { char *input, *name; int price; - if (status.num_items == 16) { + if (status.num_items == MAX_ITEMS) { cprintf("\rEs ist bereits die maximale Anzahl an Eintraegen erreicht, druecke RETURN...\r\n"); input = get_input(); return; @@ -57,7 +57,8 @@ static void new_item() { cprintf("\r\nWie oft schon verkauft? [0] \r\n"); if ((input = get_input()) == NULL || *input == '\0') return; - strcpy(status.status[status.num_items].item_name, name); + memset(status.status[status.num_items].item_name, '\0', MAX_ITEM_NAME_LENGTH+1); + strncpy(status.status[status.num_items].item_name, name, MAX_ITEM_NAME_LENGTH); status.status[status.num_items].price = price; status.status[status.num_items].times_sold = atoi(input); status.num_items++; @@ -65,7 +66,7 @@ static void new_item() { } static void _delete_item(BYTE num) { - memset(status.status[num].item_name, '\0', 10); + memset(status.status[num].item_name, '\0', MAX_ITEM_NAME_LENGTH); status.status[num].price = 0; status.status[num].times_sold = 0; } diff --git a/src/kasse.c b/src/kasse.c index 91b4a4a..c82faa9 100644 --- a/src/kasse.c +++ b/src/kasse.c @@ -238,12 +238,13 @@ void buy_custom() { BYTE c = 0, i = 0; int negative = 1; char entered[5] = {'1', 0, 0, 0, 0}; - char *input, name[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + char *input, name[20]; int price; + memset(name, '\0', 20); cprintf("\r\nWas soll gekauft werden?\r\n"); input = get_input(); - strncpy(name, input, 10); + strncpy(name, input, 20); if (*name == '\0') return; @@ -286,7 +287,7 @@ void set_time_interactive() { set_time(tp1, tp2, tp3); time = get_time(); - cprintf("Zeit gesetzt: %s\r\n", time); + cprintf("\r\nZeit gesetzt: %s\r\n", time); } int main() {