[Beignet] [PATCH] Fix PrintfState copying.

He Junyan junyan.he at inbox.com
Mon Dec 15 17:31:54 PST 2014



On 二, 2014-12-09 at 12:41 +0800, Yan Wang wrote:
> PrintfState includes std::string object and shouldn't be copied by
> malloc/memcpy.
> 
> Signed-off-by: Yan Wang <yan.wang at linux.intel.com>
> ---
>  backend/src/ir/printf.hpp | 23 +++++++++++++++++++----
>  1 file changed, 19 insertions(+), 4 deletions(-)
> 
> diff --git a/backend/src/ir/printf.hpp b/backend/src/ir/printf.hpp
> index b9f7619..8ea5976 100644
> --- a/backend/src/ir/printf.hpp
> +++ b/backend/src/ir/printf.hpp
> @@ -75,6 +75,23 @@ namespace gbe
>        char conversion_specifier;
>        int out_buf_sizeof_offset;  // Should *global_total_size to get the full offset.
>        std::string str;            //if %s, the string store here.
> +
> +      PrintfState(void) {
> +      }
I think if we consider the PrintfState as a object and use constructor
to init it, here we should better to init all the elements to default
value.

> +
> +      PrintfState(const PrintfState & other) {
> +        left_justified = other.left_justified;
> +        sign_symbol = other.sign_symbol;
> +        alter_form = other.alter_form;
> +        zero_padding = other.zero_padding;
> +        vector_n = other.vector_n;
> +        min_width = other.min_width;
> +        precision = other.precision;
> +        length_modifier = other.length_modifier;
> +        conversion_specifier = other.conversion_specifier;
> +        out_buf_sizeof_offset = other.out_buf_sizeof_offset;
> +        str = other.str;
> +      }
>      };
>  
>      enum {
> @@ -106,8 +123,7 @@ namespace gbe
>  
>        PrintfSlot(PrintfState * st) {
>          type = PRINTF_SLOT_TYPE_STATE;
> -        state = (PrintfState *)malloc(sizeof(PrintfState));
> -        memcpy(state, st, sizeof(PrintfState));
> +        state = new PrintfState(*st);
>        }
>  
>        PrintfSlot(const PrintfSlot & other) {
> @@ -119,8 +135,7 @@ namespace gbe
>            type = PRINTF_SLOT_TYPE_STRING;
>          } else if (other.type == PRINTF_SLOT_TYPE_STATE) {
>            type = PRINTF_SLOT_TYPE_STATE;
> -          state = (PrintfState *)malloc(sizeof(PrintfState));
> -          memcpy(state, other.state, sizeof(PrintfState));
> +          state = new PrintfState(*other.state);
>          } else {
>            type = PRINTF_SLOT_TYPE_NONE;
>            ptr = NULL;





More information about the Beignet mailing list