From b10579393cd0cf45b5aa80fe0e8047247a6ae0fa Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Sat, 21 Feb 2009 14:42:52 +0100 Subject: [PATCH] hdt: Sizeof have to be more explicit --- com32/hdt/hdt-cli-dmi.c | 34 +++++++++++++++++----------------- com32/hdt/hdt-cli.c | 22 +++++++++++----------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/com32/hdt/hdt-cli-dmi.c b/com32/hdt/hdt-cli-dmi.c index c232ec6..0bc2e57 100644 --- a/com32/hdt/hdt-cli-dmi.c +++ b/com32/hdt/hdt-cli-dmi.c @@ -32,73 +32,73 @@ #include void dmi_show(char *item, struct s_hardware *hardware) { - if ( !strncmp(item, CLI_DMI_BASE_BOARD, sizeof CLI_DMI_BASE_BOARD - 1) ) { + if ( !strncmp(item, CLI_DMI_BASE_BOARD, sizeof(CLI_DMI_BASE_BOARD) - 1) ) { show_dmi_base_board(hardware); return; } else - if ( !strncmp(item, CLI_DMI_SYSTEM, sizeof CLI_DMI_SYSTEM - 1) ) { + if ( !strncmp(item, CLI_DMI_SYSTEM, sizeof(CLI_DMI_SYSTEM) - 1) ) { show_dmi_system(hardware); return; } else - if ( !strncmp(item, CLI_DMI_BIOS, sizeof CLI_DMI_BIOS - 1) ) { + if ( !strncmp(item, CLI_DMI_BIOS, sizeof(CLI_DMI_BIOS) - 1) ) { show_dmi_bios(hardware); return; } else - if ( !strncmp(item, CLI_DMI_CHASSIS, sizeof CLI_DMI_CHASSIS - 1) ) { + if ( !strncmp(item, CLI_DMI_CHASSIS, sizeof(CLI_DMI_CHASSIS) - 1) ) { show_dmi_chassis(hardware); return; } else - if ( !strncmp(item, CLI_DMI_PROCESSOR, sizeof CLI_DMI_PROCESSOR - 1) ) { + if ( !strncmp(item, CLI_DMI_PROCESSOR, sizeof(CLI_DMI_PROCESSOR) - 1) ) { show_dmi_cpu(hardware); return; } - if ( !strncmp(item, CLI_DMI_MODULES, sizeof CLI_DMI_MODULES - 1) ) { + if ( !strncmp(item, CLI_DMI_MODULES, sizeof(CLI_DMI_MODULES) - 1) ) { show_dmi_modules(hardware); return; } - } + void handle_dmi_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware) { - if ( !strncmp(cli_line, CLI_SHOW, sizeof CLI_SHOW - 1) ) { - dmi_show(strstr(cli_line,"show")+ sizeof CLI_SHOW, hardware); + if ( !strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1) ) { + dmi_show(strstr(cli_line,"show")+ sizeof(CLI_SHOW), hardware); return; } } void show_dmi_modules(struct s_hardware *hardware) { char available_dmi_commands[1024]; - memset(available_dmi_commands,0,sizeof available_dmi_commands); + memset(available_dmi_commands,0,sizeof(available_dmi_commands)); if (hardware->dmi.base_board.filled==true) { - strncat(available_dmi_commands,CLI_DMI_BASE_BOARD,sizeof CLI_DMI_BASE_BOARD-1); + strncat(available_dmi_commands,CLI_DMI_BASE_BOARD,sizeof(CLI_DMI_BASE_BOARD)-1); strncat(available_dmi_commands," ",1); } if (hardware->dmi.battery.filled==true) { - strncat(available_dmi_commands,CLI_DMI_BATTERY,sizeof CLI_DMI_BATTERY-1); + strncat(available_dmi_commands,CLI_DMI_BATTERY,sizeof(CLI_DMI_BATTERY)-1); strncat(available_dmi_commands," ",1); } if (hardware->dmi.bios.filled==true) { - strncat(available_dmi_commands,CLI_DMI_BIOS,sizeof CLI_DMI_BIOS-1); + strncat(available_dmi_commands,CLI_DMI_BIOS,sizeof(CLI_DMI_BIOS)-1); strncat(available_dmi_commands," ",1); } if (hardware->dmi.chassis.filled==true) { - strncat(available_dmi_commands,CLI_DMI_CHASSIS,sizeof CLI_DMI_CHASSIS-1); + strncat(available_dmi_commands,CLI_DMI_CHASSIS,sizeof(CLI_DMI_CHASSIS)-1); strncat(available_dmi_commands," ",1); } for (int i=0;idmi.memory_count;i++) { if (hardware->dmi.memory[i].filled==true) { - strncat(available_dmi_commands,CLI_DMI_MEMORY,sizeof CLI_DMI_MEMORY-1); + strncat(available_dmi_commands,CLI_DMI_MEMORY,sizeof(CLI_DMI_MEMORY)-1); strncat(available_dmi_commands," ",1); break; } } if (hardware->dmi.processor.filled==true) { - strncat(available_dmi_commands,CLI_DMI_PROCESSOR,sizeof CLI_DMI_PROCESSOR-1); + strncat(available_dmi_commands,CLI_DMI_PROCESSOR,sizeof(CLI_DMI_PROCESSOR)-1); strncat(available_dmi_commands," ",1); } if (hardware->dmi.system.filled==true) { - strncat(available_dmi_commands,CLI_DMI_SYSTEM,sizeof CLI_DMI_SYSTEM-1); + strncat(available_dmi_commands,CLI_DMI_SYSTEM,sizeof(CLI_DMI_SYSTEM)-1); strncat(available_dmi_commands," ",1); } printf("Available DMI modules: %s\n",available_dmi_commands); diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c index 7f168bb..0497f9e 100644 --- a/com32/hdt/hdt-cli.c +++ b/com32/hdt/hdt-cli.c @@ -40,12 +40,12 @@ void set_mode(struct s_cli_mode *cli_mode, cli_mode_t mode, struct s_hardware *h case HDT_MODE: cli_mode->mode=mode; - snprintf(cli_mode->prompt, sizeof cli_mode->prompt, "%s:", CLI_HDT); + snprintf(cli_mode->prompt, sizeof(cli_mode->prompt), "%s:", CLI_HDT); break; case PCI_MODE: cli_mode->mode=mode; - snprintf(cli_mode->prompt,sizeof cli_mode->prompt,"%s:", CLI_PCI); + snprintf(cli_mode->prompt,sizeof(cli_mode->prompt),"%s:", CLI_PCI); if (!hardware->pci_detection) detect_pci(hardware); break; @@ -58,7 +58,7 @@ void set_mode(struct s_cli_mode *cli_mode, cli_mode_t mode, struct s_hardware *h break; } cli_mode->mode=mode; - snprintf(cli_mode->prompt,sizeof cli_mode->prompt,"%s:",CLI_DMI); + snprintf(cli_mode->prompt,sizeof(cli_mode->prompt),"%s:",CLI_DMI); break; } } @@ -84,7 +84,7 @@ void start_cli_mode(int argc, char *argv[]) { cli_line[strlen(cli_line)-1]='\0'; /* We use sizeof BLAH - 1 to remove the last \0 */ - if ( !strncmp(cli_line, CLI_EXIT, sizeof CLI_EXIT - 1) ) { + if ( !strncmp(cli_line, CLI_EXIT, sizeof(CLI_EXIT) - 1) ) { int mode=do_exit(&cli_mode); if (mode == EXIT_MODE) return; @@ -92,16 +92,16 @@ void start_cli_mode(int argc, char *argv[]) { continue; } - if ( !strncmp(cli_line, CLI_HELP, sizeof CLI_HELP - 1) ) { + if ( !strncmp(cli_line, CLI_HELP, sizeof(CLI_HELP) - 1) ) { show_cli_help(&cli_mode); continue; } - if ( !strncmp(cli_line, CLI_PCI, sizeof CLI_PCI - 1) ) { + if ( !strncmp(cli_line, CLI_PCI, sizeof(CLI_PCI) - 1) ) { set_mode(&cli_mode,PCI_MODE,&hardware); continue; } - if ( !strncmp(cli_line, CLI_DMI, sizeof CLI_DMI - 1) ) { + if ( !strncmp(cli_line, CLI_DMI, sizeof(CLI_DMI) - 1) ) { set_mode(&cli_mode,DMI_MODE,&hardware); continue; } @@ -109,8 +109,8 @@ void start_cli_mode(int argc, char *argv[]) { case DMI_MODE: handle_dmi_commands(cli_line,&cli_mode, &hardware); break; } - if ( !strncmp(cli_line, CLI_SHOW, sizeof CLI_SHOW - 1) ) { - main_show(strstr(cli_line,"show")+ sizeof CLI_SHOW, &hardware,&cli_mode); + if ( !strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1) ) { + main_show(strstr(cli_line,"show")+ sizeof (CLI_SHOW), &hardware,&cli_mode); continue; } @@ -141,6 +141,6 @@ switch (cli_mode->mode) { } void main_show(char *item, struct s_hardware *hardware, struct s_cli_mode *cli_mode) { - if (!strncmp(item,CLI_PCI, sizeof CLI_PCI)) main_show_pci(hardware); - if (!strncmp(item,CLI_DMI, sizeof CLI_DMI)) main_show_dmi(hardware,cli_mode); + if (!strncmp(item,CLI_PCI, sizeof (CLI_PCI))) main_show_pci(hardware); + if (!strncmp(item,CLI_DMI, sizeof (CLI_DMI))) main_show_dmi(hardware,cli_mode); } -- 2.7.4