Skip to content

Commit

Permalink
Enable warnings as error for linux/windows release builds Fix Windows…
Browse files Browse the repository at this point in the history
… and Linux build warnings Fix klocwork 4071

Signed-off-by: Kelly J Couch <[email protected]>
  • Loading branch information
kellycouch authored and gldiviney committed Nov 26, 2018
1 parent 2354bee commit b40b353
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 36 deletions.
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,18 @@ add_definitions(

# Promote warnings to errors only for release builds
if(MSVC)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /O2")
#set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /O2 /WX")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /WX")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /O2 /WX")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /WX")
set(CMAKE_C_FLAGS_DEBUG_ "${CMAKE_C_FLAGS_DEBUG} /Od")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od")
else()
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2 -fno-strict-aliasing -D_FORTIFY_SOURCE=2")
#set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2 -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -Werror")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fno-strict-aliasing -D_FORTIFY_SOURCE=2")
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -Werror")
if(LNX_BUILD)
#A few warnings yet to resolve under esx
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Werror")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Werror")
endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -ggdb")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -ggdb")
endif()
Expand Down
16 changes: 12 additions & 4 deletions DcpmPkg/cli/Common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1304,8 +1304,16 @@ FileExists(
#ifdef OS_BUILD
pFileHandle = NULL;
ReturnCode = OpenFile(pDumpUserPath, &pFileHandle, NULL, FALSE);
*pExists = ReturnCode != EFI_NOT_FOUND;
ReturnCode = EFI_SUCCESS;
if (EFI_NOT_FOUND == ReturnCode)
{
*pExists = FALSE;
ReturnCode = EFI_SUCCESS;
}
else if (EFI_SUCCESS == ReturnCode)
{
*pExists = TRUE;
pFileHandle->Close(pFileHandle);
}
#else
EFI_DEVICE_PATH_PROTOCOL *pDevicePathProtocol = NULL;
CHAR16 *pDumpFilePath = NULL;
Expand All @@ -1327,11 +1335,11 @@ FileExists(
*pExists = TRUE;
pFileHandle->Close(pFileHandle);
}
#endif

Finish:
#ifndef OS_BUILD
FREE_POOL_SAFE(pDumpFilePath);
#endif

NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
Expand Down
1 change: 1 addition & 0 deletions DcpmPkg/cli/NvmDimmCli.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "ShowHostServerCommand.h"
#include "ShowPerformanceCommand.h"
#include "ShowCmdAccessPolicyCommand.h"
#include "DeletePcdCommand.h"

#if _BullseyeCoverage
#ifndef OS_BUILD
Expand Down
2 changes: 1 addition & 1 deletion src/os/cli_cmds/DumpSupportCommand.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ DumpSupportCommand(
PrintHeaderInfo(pPrintDIMMHeaderInfo);
FREE_POOL_SAFE(pPrintDIMMHeaderInfo);
for (Index = 0; Index < MAX_DIMM_SPECIFIC_CMDS; ++Index) {
pCmdInputWithDimmId = CatSPrint(NULL, &(DumpCmdsPerDimm[Index].cmd), pDimms[DimmIndex].DimmHandle);
pCmdInputWithDimmId = CatSPrint(NULL, DumpCmdsPerDimm[Index].cmd, pDimms[DimmIndex].DimmHandle);
PrintAndExecuteCommand(pCmdInputWithDimmId);
}
if (pDictUserPath != NULL) {
Expand Down
32 changes: 17 additions & 15 deletions src/os/efi_shim/os_efi_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <conio.h>
#include <time.h>
#include <wchar.h>
#include <string.h>
#else
#include <unistd.h>
#include <wchar.h>
Expand Down Expand Up @@ -130,7 +131,7 @@ typedef struct _smbios_table_recording
#define PASS_THRU_OFFSET (ACPI_PMTT_OFFSET + ACPI_PMTT_SIZE) //40k

int g_pass_thru_cnt = 0;
size_t g_pass_thru_playback_offset = 0;
long g_pass_thru_playback_offset = 0;

#define REC_FILE_PATH g_recording_fullpath
#define PLAYBACK_ENABLED() g_playback_mode
Expand Down Expand Up @@ -206,7 +207,6 @@ EFI_STATUS init_record_file(char * recording_file_path)
EFI_STATUS update_record_size(RecordType type, FILE * file_stream, UINT32 size, BOOLEAN increment)
{
recording_file rc;
UINT32 offset;

//seek to the begining of the file
if (0 != fseek(file_stream, 0, SEEK_SET))
Expand Down Expand Up @@ -305,13 +305,13 @@ EFI_STATUS seek_to_record_offset(RecordType type, FILE * file_stream, UINT32 *re
if (0 != fseek(file_stream, 0, SEEK_SET))
{
NVDIMM_ERR("Failed seeking to the begining of the file\n");
return -1;
return EFI_DEVICE_ERROR;
}

if (1 != fread(&rc, sizeof(recording_file), 1, file_stream))
{
NVDIMM_ERR("Failed to read the recording file header\n");
return -1;
return EFI_DEVICE_ERROR;
}

switch (type)
Expand All @@ -338,14 +338,14 @@ EFI_STATUS seek_to_record_offset(RecordType type, FILE * file_stream, UINT32 *re
break;
default:
NVDIMM_ERR("Unknown record type\n");
return -1;
return EFI_INVALID_PARAMETER;
}

//seek to the begining of the record type partition
if (0 != fseek(file_stream, offset, SEEK_SET))
{
NVDIMM_ERR("Failed seeking to the begining of the file\n");
return -1;
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
Expand Down Expand Up @@ -539,7 +539,6 @@ passthru_record_finalize(
EFI_STATUS PassthruReturnCode
)
{
EFI_STATUS Rc = EFI_SUCCESS;
UINT32 total_write_sz = 0;
if (!RECORD_ENABLED())
{
Expand Down Expand Up @@ -701,18 +700,21 @@ save_table_to_file(
if (EFI_SUCCESS != (Rc = seek_to_record_offset(type, f_ptr, &record_size)))
{
NVDIMM_ERR("Failed seeking to the ACPI partition\n");
return Rc;
goto Finish;
}

if (table && 1 != fwrite(table, table->Length, 1, f_ptr))
{
Rc = EFI_END_OF_FILE;
goto Finish;
}

if (table)
{
Rc = update_record_size(type, f_ptr, table->Length, FALSE);
}

Finish:
fclose(f_ptr);
return Rc;
}
Expand Down Expand Up @@ -741,7 +743,7 @@ load_table_from_file(
if (EFI_SUCCESS != (Rc = seek_to_record_offset(type, f_ptr, &size)))
{
NVDIMM_ERR("Failed seeking to the ACPI partition\n");
return Rc;
goto Finish;
}

if (!size)
Expand All @@ -763,6 +765,7 @@ load_table_from_file(
}
}

Finish:
fclose(f_ptr);
return Rc;
}
Expand Down Expand Up @@ -883,8 +886,7 @@ GetFirstAndBoundSmBiosStructPointer(
OUT SMBIOS_VERSION *pSmbiosVersion
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;;
int rc = 0;
EFI_STATUS ReturnCode = EFI_SUCCESS;
FILE *f_ptr;
smbios_table_recording recording;
UINT32 record_size = 0;
Expand Down Expand Up @@ -926,7 +928,7 @@ GetFirstAndBoundSmBiosStructPointer(
NVDIMM_ERR("Failed to write to recording file: %s\n", REC_FILE_PATH);
ReturnCode = EFI_END_OF_FILE;
}
update_record_size(RtSmbios, f_ptr, sizeof(smbios_table_recording) + gSmbiosTableSize, FALSE);
update_record_size(RtSmbios, f_ptr, (UINT32)(sizeof(smbios_table_recording) + gSmbiosTableSize), FALSE);
}
fclose(f_ptr);
}
Expand All @@ -938,7 +940,7 @@ GetFirstAndBoundSmBiosStructPointer(
{
if (NULL == gSmbiosTable) {
//seek it to pass thru partition
if (EFI_SUCCESS != (rc = seek_to_record_offset(RtSmbios, f_ptr, &record_size)))
if (EFI_SUCCESS != seek_to_record_offset(RtSmbios, f_ptr, &record_size))
{
NVDIMM_ERR("Failed seeking to the SMBIOS partition\n");
ReturnCode = EFI_END_OF_FILE;
Expand All @@ -950,9 +952,9 @@ GetFirstAndBoundSmBiosStructPointer(
ReturnCode = EFI_END_OF_FILE;
}

if (0 == recording.size)
if (SMBIOS_SIZE < recording.size || 0 == recording.size)
{
NVDIMM_ERR("SMBIOS table in file %s reports size of 0.\n", REC_FILE_PATH);
NVDIMM_ERR("SMBIOS table in file %s reports size of %d.\n", REC_FILE_PATH, recording.size);
ReturnCode = EFI_END_OF_FILE;
}
else
Expand Down
16 changes: 16 additions & 0 deletions src/os/efi_shim/os_efi_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <Dimm.h>
#include <UefiBaseType.h>
#include <FwUtility.h>
#include <SmbiosUtility.h>
#include <time.h>

typedef enum {
Expand Down Expand Up @@ -269,4 +270,19 @@ UnicodeSPrint(
UINT32
get_first_arg_from_va_list(VA_LIST args);


/**
Fill SmBios structures for first and bound entry
@param[out] pSmBiosStruct - pointer for first SmBios entry
@param[out] pBoundSmBiosStruct - pointer for nonexistent (one after last) SmBios entry
@param[out] pSmbiosVersion - pointer to the version of SMBIOS tables retrieved
**/
EFI_STATUS
GetFirstAndBoundSmBiosStructPointer(
OUT SMBIOS_STRUCTURE_POINTER *pSmBiosStruct,
OUT SMBIOS_STRUCTURE_POINTER *pLastSmBiosStruct,
OUT SMBIOS_VERSION *pSmbiosVersion
);

#endif //OS_EFI_API_H_
14 changes: 7 additions & 7 deletions src/os/efi_shim/os_efi_preferences.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ EFI_STATUS preferences_flush_the_file(void)
EFI_STATUS preferences_get_var_ascii(IN CONST char *name,
IN CONST EFI_GUID guid,
OUT VOID *value,
OUT UINT32 *size OPTIONAL)
OUT UINTN *size OPTIONAL)
{
int val = nvm_ini_get_int_value(gIni, name, -1);
if (-1 == val)
Expand Down Expand Up @@ -102,19 +102,19 @@ EFI_STATUS preferences_get_string_ascii(IN CONST char *name,
}

EFI_STATUS preferences_get_var(IN CONST CHAR16 *name,
IN CONST EFI_GUID guid,
OUT VOID *value,
OUT UINTN *size OPTIONAL)
IN CONST EFI_GUID guid,
OUT VOID *value,
OUT UINTN *size OPTIONAL)
{
char tmp[256];
UnicodeStrToAsciiStr(name, tmp);
return preferences_get_var_ascii(tmp, guid, value, size);
}

EFI_STATUS preferences_get_var_string_wide(IN CONST CHAR16 *name,
IN CONST EFI_GUID guid,
OUT CHAR16 *value,
OUT UINTN *size OPTIONAL)
IN CONST EFI_GUID guid,
OUT CHAR16 *value,
OUT UINTN *size OPTIONAL)
{
char key[256];
const char * ascii_str;
Expand Down
2 changes: 1 addition & 1 deletion src/os/efi_shim/os_efi_preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ EFI_STATUS preferences_get_var_ascii(
IN CONST char *name,
IN CONST EFI_GUID guid,
OUT VOID *value,
OUT UINT32 *size OPTIONAL);
OUT UINTN *size OPTIONAL);

EFI_STATUS preferences_get_string_ascii(
IN CONST char *name,
Expand Down
1 change: 1 addition & 0 deletions src/os/eventlog/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <PrintLib.h>
#include "s_str.h"
#include "os.h"
#include <os_efi_api.h>

#if defined(__LINUX__)
#include <safe_str_lib.h>
Expand Down
4 changes: 2 additions & 2 deletions src/os/nvm_api/nvm_management.c
Original file line number Diff line number Diff line change
Expand Up @@ -3222,15 +3222,15 @@ NVM_API int nvm_get_fw_error_log_entry_cmd(
NVM_API int nvm_get_config_int(const char *param_name, int default_val)
{
int val = default_val;
int size = sizeof(val);
unsigned long long size = sizeof(val);
EFI_GUID g = { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } };
int rc = NVM_SUCCESS;

if (NVM_SUCCESS != (rc = nvm_init())) {
NVDIMM_ERR("Failed to intialize nvm library %d\n", rc);
return rc;
}
preferences_get_var_ascii(param_name, g, (void *)&val, (UINT32 *)&size);
preferences_get_var_ascii(param_name, g, (void *)&val, &size);
return val;
}

Expand Down

0 comments on commit b40b353

Please sign in to comment.