LKML Archive on lore.kernel.org
 help / Atom feed
* [PATCH] scripts: unifdef: fix stringop-truncation warning
@ 2018-09-14 10:44 Harshit Jain
  2018-09-14 17:12 ` Miguel Ojeda
  0 siblings, 1 reply; 6+ messages in thread
From: Harshit Jain @ 2018-09-14 10:44 UTC (permalink / raw)
  To: unlisted-recipients:; (no To-header on input)
  Cc: stable, Harshit Jain, Tony Finch, linux-kernel

From: Harshit Jain <dev-harsh1998@hotmail.com>

* This commit resolves the following warning when the mainline kernel is build with the android environment.

-> warning :-> https://gist.github.com/dev-harsh1998/757427b16a58f5498db3d87212a9651b

* This warning is persistant in all the currently maintained android kernel i.e 3.18, 4.4, 4.9, 4.14.

Signed-off-by: Harshit Jain <dev-harsh1998@hotmail.com>
---
 scripts/unifdef.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/scripts/unifdef.c b/scripts/unifdef.c
index 7493c0ee51cc..4ce008eda362 100644
--- a/scripts/unifdef.c
+++ b/scripts/unifdef.c
@@ -395,8 +395,8 @@ usage(void)
  * When we have processed a group that starts off with a known-false
  * #if/#elif sequence (which has therefore been deleted) followed by a
  * #elif that we don't understand and therefore must keep, we edit the
- * latter into a #if to keep the nesting correct. We use strncpy() to
- * overwrite the 4 byte token "elif" with "if  " without a '\0' byte.
+ * latter into a #if to keep the nesting correct. We use the memcpy() 
+ * from the string header overwrite the 4 byte token "elif" with "if  ".
  *
  * When we find a true #elif in a group, the following block will
  * always be kept and the rest of the sequence after the next #elif or
@@ -450,7 +450,7 @@ static void Idrop (void) { Fdrop();  ignoreon(); }
 static void Itrue (void) { Ftrue();  ignoreon(); }
 static void Ifalse(void) { Ffalse(); ignoreon(); }
 /* modify this line */
-static void Mpass (void) { strncpy(keyword, "if  ", 4); Pelif(); }
+static void Mpass (void) { memcpy(keyword, "if  ", 4); Pelif(); }
 static void Mtrue (void) { keywordedit("else");  state(IS_TRUE_MIDDLE); }
 static void Melif (void) { keywordedit("endif"); state(IS_FALSE_TRAILER); }
 static void Melse (void) { keywordedit("endif"); state(IS_FALSE_ELSE); }
-- 
2.18.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] scripts: unifdef: fix stringop-truncation warning
  2018-09-14 10:44 [PATCH] scripts: unifdef: fix stringop-truncation warning Harshit Jain
@ 2018-09-14 17:12 ` Miguel Ojeda
  2018-09-14 17:18   ` Miguel Ojeda
  0 siblings, 1 reply; 6+ messages in thread
From: Miguel Ojeda @ 2018-09-14 17:12 UTC (permalink / raw)
  To: Harshit Jain; +Cc: stable, Harshit Jain, Tony Finch, linux-kernel

Hi Harshit,

On Fri, Sep 14, 2018 at 12:44 PM, Harshit Jain
<harshitjain6751@gmail.com> wrote:
> From: Harshit Jain <dev-harsh1998@hotmail.com>
>
> * This commit resolves the following warning when the mainline kernel is build with the android environment.

Typo: built

>
> -> warning :-> https://gist.github.com/dev-harsh1998/757427b16a58f5498db3d87212a9651b

Try to avoid links to external pages (specially if they are only 2 lines :-).

>
> * This warning is persistant in all the currently maintained android kernel i.e 3.18, 4.4, 4.9, 4.14.

Typos: persistent, kernels, i.e.

>
> Signed-off-by: Harshit Jain <dev-harsh1998@hotmail.com>
> ---
>  scripts/unifdef.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/unifdef.c b/scripts/unifdef.c
> index 7493c0ee51cc..4ce008eda362 100644
> --- a/scripts/unifdef.c
> +++ b/scripts/unifdef.c
> @@ -395,8 +395,8 @@ usage(void)
>   * When we have processed a group that starts off with a known-false
>   * #if/#elif sequence (which has therefore been deleted) followed by a
>   * #elif that we don't understand and therefore must keep, we edit the
> - * latter into a #if to keep the nesting correct. We use strncpy() to
> - * overwrite the 4 byte token "elif" with "if  " without a '\0' byte.
> + * latter into a #if to keep the nesting correct. We use the memcpy()
> + * from the string header overwrite the 4 byte token "elif" with "if  ".
>   *
>   * When we find a true #elif in a group, the following block will
>   * always be kept and the rest of the sequence after the next #elif or
> @@ -450,7 +450,7 @@ static void Idrop (void) { Fdrop();  ignoreon(); }
>  static void Itrue (void) { Ftrue();  ignoreon(); }
>  static void Ifalse(void) { Ffalse(); ignoreon(); }
>  /* modify this line */
> -static void Mpass (void) { strncpy(keyword, "if  ", 4); Pelif(); }
> +static void Mpass (void) { memcpy(keyword, "if  ", 4); Pelif(); }

Seems like keyword shouldn't use __attribute__((nonstring)), so this
looks right.

Cheers,
Miguel

>  static void Mtrue (void) { keywordedit("else");  state(IS_TRUE_MIDDLE); }
>  static void Melif (void) { keywordedit("endif"); state(IS_FALSE_TRAILER); }
>  static void Melse (void) { keywordedit("endif"); state(IS_FALSE_ELSE); }
> --
> 2.18.0
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] scripts: unifdef: fix stringop-truncation warning
  2018-09-14 17:12 ` Miguel Ojeda
@ 2018-09-14 17:18   ` Miguel Ojeda
  0 siblings, 0 replies; 6+ messages in thread
From: Miguel Ojeda @ 2018-09-14 17:18 UTC (permalink / raw)
  To: Harshit Jain; +Cc: stable, Harshit Jain, Tony Finch, linux-kernel

On Fri, Sep 14, 2018 at 7:12 PM, Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
> Hi Harshit,

Another two nitpicks:

  * Since this is the second version of the patch, write "[PATCH v2]"
in the title instead; that way people know you have sent an earlier
version. On top of that, you should explain the differences between
each version after the "---" line (i.e. the part that does not belong
to the commit message).

  * You may want to write down who you CC'd (e.g. Tony and the stable
mailing list) in "Cc: ..." lines before the Signed-off-by line.

Thanks for the patch!

Hope that helps,
Miguel

>
> On Fri, Sep 14, 2018 at 12:44 PM, Harshit Jain
> <harshitjain6751@gmail.com> wrote:
>> From: Harshit Jain <dev-harsh1998@hotmail.com>
>>
>> * This commit resolves the following warning when the mainline kernel is build with the android environment.
>
> Typo: built
>
>>
>> -> warning :-> https://gist.github.com/dev-harsh1998/757427b16a58f5498db3d87212a9651b
>
> Try to avoid links to external pages (specially if they are only 2 lines :-).
>
>>
>> * This warning is persistant in all the currently maintained android kernel i.e 3.18, 4.4, 4.9, 4.14.
>
> Typos: persistent, kernels, i.e.
>
>>
>> Signed-off-by: Harshit Jain <dev-harsh1998@hotmail.com>
>> ---
>>  scripts/unifdef.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/scripts/unifdef.c b/scripts/unifdef.c
>> index 7493c0ee51cc..4ce008eda362 100644
>> --- a/scripts/unifdef.c
>> +++ b/scripts/unifdef.c
>> @@ -395,8 +395,8 @@ usage(void)
>>   * When we have processed a group that starts off with a known-false
>>   * #if/#elif sequence (which has therefore been deleted) followed by a
>>   * #elif that we don't understand and therefore must keep, we edit the
>> - * latter into a #if to keep the nesting correct. We use strncpy() to
>> - * overwrite the 4 byte token "elif" with "if  " without a '\0' byte.
>> + * latter into a #if to keep the nesting correct. We use the memcpy()
>> + * from the string header overwrite the 4 byte token "elif" with "if  ".
>>   *
>>   * When we find a true #elif in a group, the following block will
>>   * always be kept and the rest of the sequence after the next #elif or
>> @@ -450,7 +450,7 @@ static void Idrop (void) { Fdrop();  ignoreon(); }
>>  static void Itrue (void) { Ftrue();  ignoreon(); }
>>  static void Ifalse(void) { Ffalse(); ignoreon(); }
>>  /* modify this line */
>> -static void Mpass (void) { strncpy(keyword, "if  ", 4); Pelif(); }
>> +static void Mpass (void) { memcpy(keyword, "if  ", 4); Pelif(); }
>
> Seems like keyword shouldn't use __attribute__((nonstring)), so this
> looks right.
>
> Cheers,
> Miguel
>
>>  static void Mtrue (void) { keywordedit("else");  state(IS_TRUE_MIDDLE); }
>>  static void Melif (void) { keywordedit("endif"); state(IS_FALSE_TRAILER); }
>>  static void Melse (void) { keywordedit("endif"); state(IS_FALSE_ELSE); }
>> --
>> 2.18.0
>>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] scripts: unifdef: fix stringop-truncation warning
       [not found]   ` <CAA47fTLj32cf=p5LUwZDrtKvXebHDNxz9ozEz9YCoCFP0NRgng@mail.gmail.com>
@ 2018-08-23 11:42     ` Tony Finch
  0 siblings, 0 replies; 6+ messages in thread
From: Tony Finch @ 2018-08-23 11:42 UTC (permalink / raw)
  To: Harshit Jain; +Cc: linux-kernel

Harshit Jain <harshitjain6751@gmail.com> wrote:

> Hey! tony thanks for reviewing, pardon me i wasn't able to get your context
> can you please elaborate a little what you are trying to say?

There's a big block comment above the state machine code which tries to
explain what the blazes is going on. The comment includes an explanation
of the weird strncpy() call, which you need to update to talk about
memcpy() instead.

(The code is heavily compactified because I wrote it on a laptop with a
small screen and I needed to be able to see it all to understand it!)

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
South Fitzroy: Northerly or northeasterly 5 or 6. Slight or moderate.
Occasional drizzle. Good, occasionally poor at first.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] scripts: unifdef: fix stringop-truncation warning
  2018-08-17 20:20 Harshit Jain
@ 2018-08-21 15:13 ` Tony Finch
       [not found]   ` <CAA47fTLj32cf=p5LUwZDrtKvXebHDNxz9ozEz9YCoCFP0NRgng@mail.gmail.com>
  0 siblings, 1 reply; 6+ messages in thread
From: Tony Finch @ 2018-08-21 15:13 UTC (permalink / raw)
  To: Harshit Jain; +Cc: linux-kernel, Tony Finch

Harshit Jain <harshitjain6751@gmail.com> wrote:

>  /* modify this line */
> -static void Mpass (void) { strncpy(keyword, "if  ", 4); Pelif(); }
> +static void Mpass (void) { memcpy(keyword, "if  ", 4); Pelif(); }

Yes, this is a good improvement, but you also need to update the comment
to match the code.

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
Wight, Portland, Plymouth: Westerly 3 or 4, occasionally 5 in north. Slight,
occasionally moderate. Drizzle, fog banks. Moderate, occasionally very poor.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] scripts: unifdef: fix stringop-truncation warning
@ 2018-08-17 20:20 Harshit Jain
  2018-08-21 15:13 ` Tony Finch
  0 siblings, 1 reply; 6+ messages in thread
From: Harshit Jain @ 2018-08-17 20:20 UTC (permalink / raw)
  To: unlisted-recipients:; (no To-header on input)
  Cc: Harshit Jain, Tony Finch, linux-kernel

While compiling the mainline kernel in android env with latest gcc 8 the compiler threw this warning Thanks to the advantage of improved static analysis in newer gcc we are now able to
see this warning this patch resolves the detected compiler warnings.

Signed-off-by: Harshit Jain <harshitjain6751@gmail.com>
---
 scripts/unifdef.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/unifdef.c b/scripts/unifdef.c
index 7493c0ee51cc..985649805cdd 100644
--- a/scripts/unifdef.c
+++ b/scripts/unifdef.c
@@ -450,7 +450,7 @@ static void Idrop (void) { Fdrop();  ignoreon(); }
 static void Itrue (void) { Ftrue();  ignoreon(); }
 static void Ifalse(void) { Ffalse(); ignoreon(); }
 /* modify this line */
-static void Mpass (void) { strncpy(keyword, "if  ", 4); Pelif(); }
+static void Mpass (void) { memcpy(keyword, "if  ", 4); Pelif(); }
 static void Mtrue (void) { keywordedit("else");  state(IS_TRUE_MIDDLE); }
 static void Melif (void) { keywordedit("endif"); state(IS_FALSE_TRAILER); }
 static void Melse (void) { keywordedit("endif"); state(IS_FALSE_ELSE); }
-- 
2.18.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-14 10:44 [PATCH] scripts: unifdef: fix stringop-truncation warning Harshit Jain
2018-09-14 17:12 ` Miguel Ojeda
2018-09-14 17:18   ` Miguel Ojeda
  -- strict thread matches above, loose matches on Subject: below --
2018-08-17 20:20 Harshit Jain
2018-08-21 15:13 ` Tony Finch
     [not found]   ` <CAA47fTLj32cf=p5LUwZDrtKvXebHDNxz9ozEz9YCoCFP0NRgng@mail.gmail.com>
2018-08-23 11:42     ` Tony Finch

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org linux-kernel@archiver.kernel.org
	public-inbox-index lkml


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox