[prev in list] [next in list] [prev in thread] [next in thread] 

List:       oprofile-list
Subject:    Re: oprofile - fix compiler warnings seen with newer gcc
From:       William Cohen <wcohen () redhat ! com>
Date:       2019-04-30 15:51:17
Message-ID: da445fbd-eb82-82a5-570a-1f5177df7903 () redhat ! com
[Download RAW message or body]

On 4/29/19 6:18 PM, will schmidt wrote:
> Hi, 
> 
> This is intended to fix some compiler warnings noted when building oprofile with \
> gcc 9.0.1 
> * libutil++/tests/utility_tests.cpp:  Remove deprecated dynamic exception
> specifications. (gcc -Werror=deprecated).
> * libpe_utils/op_pe_utils.cpp: strncpy already copies the size of the
> string, limit it to the size of the destination.
> * opjitconf/opjitconv.c:  convert sprintf to snprintf and check the return
> length from the call to ensure we do not overrun our buffer.
> (gcc -Werror=format-overflow)
> 
> ---
> Thanks
> -Will

Hi Will,

The changes look fine.  There are committed to the mainline oprofile git repository.  \
Thanks,  -Will Cohen

> 
> 
> diff --git a/libpe_utils/op_pe_utils.cpp b/libpe_utils/op_pe_utils.cpp
> index 2cae784..d545cee 100644
> --- a/libpe_utils/op_pe_utils.cpp
> +++ b/libpe_utils/op_pe_utils.cpp
> @@ -652,11 +652,11 @@ static bool _get_codes_for_match(unsigned int pfm_idx, const \
> char name[],  strcpy(evt_name ,"PM_CYC") ;
> 		} else if (strstr(event.name, "_GRP")) {
> 			string str = event.name;
> 			strncpy(evt_name, event.name, str.rfind("_GRP"));
> 		} else {
> -			strncpy(evt_name, event.name, strlen(event.name));
> +			strncpy(evt_name, event.name, strlen(evt_name));
> 		}
> 
> 		/* Events where the "_EDGE_COUNT" suffix has been appended to a
> 		 * real native event name are pseudo events (events that have
> 		 * not been formally defined in processor documentation), where
> @@ -732,11 +732,11 @@ static bool _op_get_event_codes(vector<operf_event_t> * \
> evt_vec)  strcpy(evt_name ,"PM_CYC") ;
> 		} else if (strstr(event.name, "_GRP")) {
> 			string str = event.name;
> 			strncpy(evt_name, event.name, str.rfind("_GRP"));
> 		} else {
> -			strncpy(evt_name, event.name, strlen(event.name));
> +			strncpy(evt_name, event.name, sizeof(evt_name));
> 		}
> 
> 		/* Events where the "_EDGE_COUNT" suffix has been appended to a
> 		 * real native event name are pseudo events (events that have
> 		 * not been formally defined in processor documentation), where
> diff --git a/libutil++/tests/utility_tests.cpp b/libutil++/tests/utility_tests.cpp
> index 3955fd0..2f8286f 100644
> --- a/libutil++/tests/utility_tests.cpp
> +++ b/libutil++/tests/utility_tests.cpp
> @@ -19,17 +19,17 @@
> using namespace std;
> 
> static int nb_new;
> static int nb_new_array;
> 
> -void* operator new(size_t size) throw(bad_alloc)
> +void* operator new(size_t size)
> {
> 	nb_new++;
> 	return malloc(size);
> }
> 
> -void* operator new[](size_t size) throw(bad_alloc)
> +void* operator new[](size_t size)
> {
> 	nb_new_array++;
> 	return malloc(size);
> }
> 
> diff --git a/opjitconv/opjitconv.c b/opjitconv/opjitconv.c
> index 207054a..c55d8b1 100644
> --- a/opjitconv/opjitconv.c
> +++ b/opjitconv/opjitconv.c
> @@ -720,12 +720,12 @@ static int op_process_jit_dumpfiles(char const * session_dir,
> 	
> rm_tmp:
> 	/* Delete temporary working directory with all its files
> 	 * (i.e. dump and ELF file).
> 	 */
> -	sprintf(sys_cmd_buffer, "/bin/rm -rf '%s'", tmp_conv_dir);
> -	if (system(sys_cmd_buffer) != 0) {
> +	retlen=snprintf(sys_cmd_buffer,sizeof(sys_cmd_buffer), "/bin/rm -rf '%s'", \
> tmp_conv_dir); +	if ((retlen <=0 ) || (system(sys_cmd_buffer) != 0)) {
> 		printf("opjitconv: Removing temporary working directory failed.\n");
> 		rc = OP_JIT_CONV_TMPDIR_NOT_REMOVED;
> 	}
> 	
> out:
> 
> 
> 
> _______________________________________________
> oprofile-list mailing list
> oprofile-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/oprofile-list
> 



_______________________________________________
oprofile-list mailing list
oprofile-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oprofile-list


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic