All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky at gmail.com>
To: powertop@lists.01.org
Subject: Re: [Powertop] [PATCH v2 5/8] Limit sprintf to buffer size length.
Date: Wed, 15 Oct 2014 21:15:57 +0900	[thread overview]
Message-ID: <20141015121557.GA1189@swordfish> (raw)
In-Reply-To: 1413310159-30577-6-git-send-email-joe.konno@linux.intel.com

[-- Attachment #1: Type: text/plain, Size: 1667 bytes --]

On (10/14/14 11:09), Joe Konno wrote:
> Not completely needed, but good practice.  Limiting sprintf to the
> length of the buffer size.  This patch not completely necessary as it's
> unlikely to be an issue here.
> 
> v2: rebase atop 41c54e8; adaptated to newer context
> 
> Signed-off-by: Joe Konno <joe.konno(a)intel.com>
> ---
>  src/lib.cpp | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/src/lib.cpp b/src/lib.cpp
> index 437803b..9cbf78d 100644
> --- a/src/lib.cpp
> +++ b/src/lib.cpp
> @@ -474,10 +474,10 @@ int read_msr(int cpu, uint64_t offset, uint64_t *value)
>  	int fd;
>  	char msr_path[256];
>  
> -	sprintf(msr_path, "/dev/cpu/%d/msr", cpu);
> +	fd = snprintf(msr_path, 256, "/dev/cpu/%d/msr", cpu);

iirc, this `fd =' has been removed. it's useless per se.

	-ss

>  	if (access(msr_path, R_OK) != 0){
> -		sprintf(msr_path, "/dev/msr%d", cpu);
> +		fd = snprintf(msr_path, 256, "/dev/msr%d", cpu);
>  
>  		if (access(msr_path, R_OK) != 0){
>  			fprintf(stderr,
> @@ -506,10 +506,10 @@ int write_msr(int cpu, uint64_t offset, uint64_t value)
>  	int fd;
>  	char msr_path[256];
>  
> -	sprintf(msr_path, "/dev/cpu/%d/msr", cpu);
> +	fd = snprintf(msr_path, 256, "/dev/cpu/%d/msr", cpu);
>  
>  	if (access(msr_path, R_OK) != 0){
> -		sprintf(msr_path, "/dev/msr%d", cpu);
> +		fd = snprintf(msr_path, 256, "/dev/msr%d", cpu);
>  
>  		if (access(msr_path, R_OK) != 0){
>  			fprintf(stderr,
> -- 
> 2.1.2
> 
> _______________________________________________
> PowerTop mailing list
> PowerTop(a)lists.01.org
> https://lists.01.org/mailman/listinfo/powertop
> 

             reply	other threads:[~2014-10-15 12:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-15 12:15 Sergey Senozhatsky [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-10-17 17:36 [Powertop] [PATCH v2 5/8] Limit sprintf to buffer size length Joe Konno
2014-10-14 18:09 Joe Konno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141015121557.GA1189@swordfish \
    --to=powertop@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.