diff mbox series

[v1,8/8] migration: use pstrcpy to copy run state

Message ID 20200903112107.27367-9-alex.bennee@linaro.org
State New
Headers show
Series some testing and CI updates (re-greening) | expand

Commit Message

Alex Bennée Sept. 3, 2020, 11:21 a.m. UTC
The gcov build triggered:

  ../../migration/global_state.c:47:5: error: ‘strncpy’ specified
      bound 100 equals destination size [-Werror=stringop-truncation]
      strncpy((char *)global_state.runstate

As we shouldn't be using strncpy anyway lets use the suggested
pstrcpy.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
 migration/global_state.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

-- 
2.20.1

Comments

Paolo Bonzini Sept. 3, 2020, 12:13 p.m. UTC | #1
Il gio 3 set 2020, 13:21 Alex Bennée <alex.bennee@linaro.org> ha scritto:

> The gcov build triggered:

>

>   ../../migration/global_state.c:47:5: error: ‘strncpy’ specified

>       bound 100 equals destination size [-Werror=stringop-truncation]

>       strncpy((char *)global_state.runstate

>

> As we shouldn't be using strncpy anyway lets use the suggested

> pstrcpy.

>


This is wrong, we want the all-zeros behavior of strncpy that pstrcpy lacks.

Paolo


>

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> ---

>  migration/global_state.c | 4 ++--

>  1 file changed, 2 insertions(+), 2 deletions(-)

>

> diff --git a/migration/global_state.c b/migration/global_state.c

> index 25311479a4b..5fbe6d1ff07 100644

> --- a/migration/global_state.c

> +++ b/migration/global_state.c

> @@ -44,8 +44,8 @@ void global_state_store_running(void)

>  {

>      const char *state = RunState_str(RUN_STATE_RUNNING);

>      assert(strlen(state) < sizeof(global_state.runstate));

> -    strncpy((char *)global_state.runstate,

> -           state, sizeof(global_state.runstate));

> +    pstrcpy((char *)global_state.runstate, sizeof(global_state.runstate),

> +            state);

>  }

>

>  bool global_state_received(void)

> --

> 2.20.1

>

>
<div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il gio 3 set 2020, 13:21 Alex Bennée &lt;<a href="mailto:alex.bennee@linaro.org">alex.bennee@linaro.org</a>&gt; ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The gcov build triggered:<br>
<br>
  ../../migration/global_state.c:47:5: error: ‘strncpy’ specified<br>
      bound 100 equals destination size [-Werror=stringop-truncation]<br>
      strncpy((char *)global_state.runstate<br>
<br>
As we shouldn&#39;t be using strncpy anyway lets use the suggested<br>
pstrcpy.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">This is wrong, we want the all-zeros behavior of strncpy that pstrcpy lacks.</div><div dir="auto"><br></div><div dir="auto">Paolo</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br><br>
Signed-off-by: Alex Bennée &lt;<a href="mailto:alex.bennee@linaro.org" target="_blank" rel="noreferrer">alex.bennee@linaro.org</a>&gt;<br>

---<br>
 migration/global_state.c | 4 ++--<br>
 1 file changed, 2 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/migration/global_state.c b/migration/global_state.c<br>
index 25311479a4b..5fbe6d1ff07 100644<br>
--- a/migration/global_state.c<br>
+++ b/migration/global_state.c<br>
@@ -44,8 +44,8 @@ void global_state_store_running(void)<br>
 {<br>
     const char *state = RunState_str(RUN_STATE_RUNNING);<br>
     assert(strlen(state) &lt; sizeof(global_state.runstate));<br>
-    strncpy((char *)global_state.runstate,<br>
-           state, sizeof(global_state.runstate));<br>
+    pstrcpy((char *)global_state.runstate, sizeof(global_state.runstate),<br>
+            state);<br>
 }<br>
<br>
 bool global_state_received(void)<br>
-- <br>
2.20.1<br>
<br>
</blockquote></div></div></div>
Philippe Mathieu-Daudé Sept. 3, 2020, 7:43 p.m. UTC | #2
On 9/3/20 2:13 PM, Paolo Bonzini wrote:
> Il gio 3 set 2020, 13:21 Alex Bennée <alex.bennee@linaro.org

> <mailto:alex.bennee@linaro.org>> ha scritto:

> 

>     The gcov build triggered:

> 

>       ../../migration/global_state.c:47:5: error: ‘strncpy’ specified

>           bound 100 equals destination size [-Werror=stringop-truncation]

>           strncpy((char *)global_state.runstate

> 

>     As we shouldn't be using strncpy anyway lets use the suggested

>     pstrcpy.

> 

> 

> This is wrong, we want the all-zeros behavior of strncpy that pstrcpy lacks.


FWIW links to previous discussions:
https://www.mail-archive.com/qemu-devel@nongnu.org/msg584216.html

> 

> Paolo
Alex Bennée Sept. 4, 2020, 10:03 a.m. UTC | #3
Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> On 9/3/20 2:13 PM, Paolo Bonzini wrote:

>> Il gio 3 set 2020, 13:21 Alex Bennée <alex.bennee@linaro.org

>> <mailto:alex.bennee@linaro.org>> ha scritto:

>> 

>>     The gcov build triggered:

>> 

>>       ../../migration/global_state.c:47:5: error: ‘strncpy’ specified

>>           bound 100 equals destination size [-Werror=stringop-truncation]

>>           strncpy((char *)global_state.runstate

>> 

>>     As we shouldn't be using strncpy anyway lets use the suggested

>>     pstrcpy.

>> 

>> 

>> This is wrong, we want the all-zeros behavior of strncpy that pstrcpy lacks.

>

> FWIW links to previous discussions:

> https://www.mail-archive.com/qemu-devel@nongnu.org/msg584216.html


Hmm I wonder why gprof interfered with the assert. Either way I'll drop
the patch.

>

>> 

>> Paolo



-- 
Alex Bennée
diff mbox series

Patch

diff --git a/migration/global_state.c b/migration/global_state.c
index 25311479a4b..5fbe6d1ff07 100644
--- a/migration/global_state.c
+++ b/migration/global_state.c
@@ -44,8 +44,8 @@  void global_state_store_running(void)
 {
     const char *state = RunState_str(RUN_STATE_RUNNING);
     assert(strlen(state) < sizeof(global_state.runstate));
-    strncpy((char *)global_state.runstate,
-           state, sizeof(global_state.runstate));
+    pstrcpy((char *)global_state.runstate, sizeof(global_state.runstate),
+            state);
 }
 
 bool global_state_received(void)