Fixing tool erros (#1416)
Tools running for sanity checks are detecting buffer overrun which is not the case. Still getting rid of function which is causing the issue removed and making the code more robust using defensive programming so that any tool is not able to detect issues hereafter. Fixed comments, corrected typos and added a new return type which is required as per refactoring Signed-off-by: Ashutosh Mishra <ashutosh.mishra@amd.com>
This commit is contained in:
committad av
GitHub
förälder
ba5b8aa16f
incheckning
221807b69d
@@ -1,8 +1,7 @@
|
||||
/*
|
||||
Copyright © Advanced Micro Devices, Inc., or its affiliates.
|
||||
//Copyright © Advanced Micro Devices, Inc., or its affiliates.
|
||||
|
||||
SPDX-License-Identifier: MIT
|
||||
*/
|
||||
//SPDX-License-Identifier: MIT
|
||||
|
||||
|
||||
#include "rocm_version.h"
|
||||
#include <string.h>
|
||||
@@ -10,12 +9,17 @@ SPDX-License-Identifier: MIT
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#define NULL_CHECK(ptr) if(!ptr) return VerIncorrecPararmeters;
|
||||
#define NULL_CHECK(ptr) if(!ptr) return VerIncorrectParameters;
|
||||
|
||||
|
||||
#define CHECK_AND_REPORT_API_RESULT(val) do { \
|
||||
if(VerSuccess != val) { \
|
||||
const char *ErrStrings[VerErrorMAX]= { "VerSuccess", "VerIncorrecPararmeters", "VerValuesNotDefined" }; \
|
||||
const char *ErrStrings[VerErrorMAX]= { \
|
||||
"VerSuccess", \
|
||||
"VerIncorrectParameters", \
|
||||
"VerMemoryAllocationFailed", \
|
||||
"VerValuesNotDefined" \
|
||||
}; \
|
||||
fprintf(stderr, " API returned : %s \n", ErrStrings[val]); \
|
||||
fflush(stderr); \
|
||||
return val; \
|
||||
@@ -37,45 +41,45 @@ VerErrors getROCmVersion(unsigned int* Major, unsigned int* Minor, unsigned int*
|
||||
return VerSuccess;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static VerErrors getBuildInfoLen( int* InfoStrlen ) {
|
||||
|
||||
NULL_CHECK(InfoStrlen);
|
||||
#if defined(ROCM_BUILD_INFO)
|
||||
*InfoStrlen = 1 + strlen(ROCM_BUILD_INFO);//additional char for null termination
|
||||
#else
|
||||
return VerValuesNotDefined;
|
||||
#endif //end defination checker
|
||||
return VerSuccess;
|
||||
}
|
||||
|
||||
static VerErrors getBuildInfo( char* InfoString, int len ) {
|
||||
|
||||
static VerErrors getBuildInfo( char* InfoString, int length_of_the_buffer ) {
|
||||
NULL_CHECK(InfoString);
|
||||
#if defined(ROCM_BUILD_INFO)
|
||||
snprintf(InfoString, len, "%s", ROCM_BUILD_INFO);
|
||||
if(length_of_the_buffer<=strlen(ROCM_BUILD_INFO)){
|
||||
fprintf(stderr, "\n Error :: Buffer is less than adequate size required\n");
|
||||
fflush(stderr);
|
||||
return VerIncorrectParameters;
|
||||
}
|
||||
snprintf(InfoString, length_of_the_buffer, "%s", ROCM_BUILD_INFO);
|
||||
return VerSuccess;
|
||||
#else
|
||||
return VerValuesNotDefined;
|
||||
#endif //end defination checker
|
||||
return VerSuccess;
|
||||
#endif //end definition checker
|
||||
}
|
||||
|
||||
VerErrors printBuildInfo() {
|
||||
int len_of_buffer_to_be_created = 0;
|
||||
VerErrors apiret=VerSuccess;
|
||||
|
||||
int lenstr=0;
|
||||
VerErrors apiret=VerSuccess;
|
||||
#if defined(ROCM_BUILD_INFO)
|
||||
len_of_buffer_to_be_created = 1 + strlen(ROCM_BUILD_INFO);//additional char for null termination
|
||||
#else
|
||||
return VerValuesNotDefined;
|
||||
#endif //end definition checker
|
||||
|
||||
apiret=getBuildInfoLen(&lenstr);
|
||||
CHECK_AND_REPORT_API_RESULT(apiret);
|
||||
|
||||
char* cstr=(char*) malloc(lenstr*sizeof(char));
|
||||
apiret=getBuildInfo(cstr,lenstr);
|
||||
CHECK_AND_REPORT_API_RESULT(apiret);
|
||||
|
||||
printf("\n Build Info of lib = [%s] \n",cstr);
|
||||
|
||||
free(cstr);
|
||||
|
||||
return VerSuccess;
|
||||
// len_of_buffer_to_be_created is now strlen(ROCM_BUILD_INFO) + 1
|
||||
char* cstr=(char*) malloc(len_of_buffer_to_be_created);
|
||||
if(cstr){
|
||||
apiret=getBuildInfo(cstr,len_of_buffer_to_be_created);
|
||||
if(VerSuccess != apiret) {
|
||||
free(cstr);
|
||||
}
|
||||
CHECK_AND_REPORT_API_RESULT(apiret);
|
||||
printf("\n Build Info of lib = [%s] \n",cstr);
|
||||
//All good lets free
|
||||
free(cstr);
|
||||
return VerSuccess;
|
||||
}
|
||||
fprintf(stderr, "\n malloc failed for length [%d] \n",len_of_buffer_to_be_created);
|
||||
fflush(stderr);
|
||||
return VerMemoryAllocationFailed;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif // __cplusplus
|
||||
|
||||
|
||||
#define LIB_API_PUBLIC __attribute__ ((visibility ("default")))
|
||||
@@ -44,14 +44,15 @@ extern "C" {
|
||||
|
||||
typedef enum {
|
||||
VerSuccess=0,
|
||||
VerIncorrecPararmeters,
|
||||
VerIncorrectParameters,
|
||||
VerMemoryAllocationFailed,
|
||||
VerValuesNotDefined,
|
||||
VerErrorMAX //This should always be last value in the enumerations
|
||||
} VerErrors;
|
||||
|
||||
|
||||
// API for getting the verion
|
||||
// Return val : VerErros : API execution status. The parameters are valid only when the exetution status is SUCCESS==0
|
||||
// API for getting the version
|
||||
// Return val : VerErrors : API execution status. The parameters are valid only when the exetution status is SUCCESS==0
|
||||
LIB_API_PUBLIC VerErrors getROCmVersion(unsigned int* Major, unsigned int* Minor, unsigned int* Patch) __attribute__((nonnull)) ;
|
||||
// Usage :
|
||||
// int mj=0,mn=0,p=0,ret=0;
|
||||
|
||||
Referens i nytt ärende
Block a user