Re: [Mesa-dev] [PATCH] i965: Initialize new chunks of realloc'd memory.

2014-07-14 Thread Kenneth Graunke
On Wednesday, July 09, 2014 12:41:25 PM Matt Turner wrote:
> Otherwise we'd compare uninitialized pointers with NULL and dereference,
> leading to crashes.
> ---
>  src/mesa/drivers/dri/i965/intel_asm_annotation.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/src/mesa/drivers/dri/i965/intel_asm_annotation.c 
b/src/mesa/drivers/dri/i965/intel_asm_annotation.c
> index 4717baf..6a51d89 100644
> --- a/src/mesa/drivers/dri/i965/intel_asm_annotation.c
> +++ b/src/mesa/drivers/dri/i965/intel_asm_annotation.c
> @@ -96,11 +96,15 @@ void annotate(struct brw_context *brw,
>struct backend_instruction *inst, unsigned offset)
>  {
> if (annotation->ann_size <= annotation->ann_count) {
> +  int old_size = annotation->ann_size;
>annotation->ann_size = MAX2(1024, annotation->ann_size * 2);
>annotation->ann = reralloc(annotation->mem_ctx, annotation->ann,
>   struct annotation, annotation->ann_size);
>if (!annotation->ann)
>   return;
> +
> +  memset(annotation->ann + old_size, 0,
> + (annotation->ann_size - old_size) * sizeof(struct 
annotation));
> }
>  
> struct annotation *ann = &annotation->ann[annotation->ann_count++];
> 

Reviewed-by: Kenneth Graunke 

signature.asc
Description: This is a digitally signed message part.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] i965: Initialize new chunks of realloc'd memory.

2014-07-09 Thread Matt Turner
Otherwise we'd compare uninitialized pointers with NULL and dereference,
leading to crashes.
---
 src/mesa/drivers/dri/i965/intel_asm_annotation.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/intel_asm_annotation.c 
b/src/mesa/drivers/dri/i965/intel_asm_annotation.c
index 4717baf..6a51d89 100644
--- a/src/mesa/drivers/dri/i965/intel_asm_annotation.c
+++ b/src/mesa/drivers/dri/i965/intel_asm_annotation.c
@@ -96,11 +96,15 @@ void annotate(struct brw_context *brw,
   struct backend_instruction *inst, unsigned offset)
 {
if (annotation->ann_size <= annotation->ann_count) {
+  int old_size = annotation->ann_size;
   annotation->ann_size = MAX2(1024, annotation->ann_size * 2);
   annotation->ann = reralloc(annotation->mem_ctx, annotation->ann,
  struct annotation, annotation->ann_size);
   if (!annotation->ann)
  return;
+
+  memset(annotation->ann + old_size, 0,
+ (annotation->ann_size - old_size) * sizeof(struct annotation));
}
 
struct annotation *ann = &annotation->ann[annotation->ann_count++];
-- 
1.8.5.5

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] i965: Initialize new chunks of realloc'd memory.

2014-07-08 Thread Matt Turner
On Tue, Jul 8, 2014 at 9:51 PM, Chris Forbes  wrote:
> I think you want to move the memset after the !annotation->ann bail
> out. Currently, if that allocation were to fail (and we care enough to
> check...) , you'll segfault.

Yeah... of course.

Thanks.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] i965: Initialize new chunks of realloc'd memory.

2014-07-08 Thread Chris Forbes
I think you want to move the memset after the !annotation->ann bail
out. Currently, if that allocation were to fail (and we care enough to
check...) , you'll segfault.

On Wed, Jul 9, 2014 at 3:44 PM, Matt Turner  wrote:
> Otherwise we'd compare uninitialized pointers with NULL and dereference,
> leading to crashes.
> ---
>  src/mesa/drivers/dri/i965/intel_asm_annotation.c | 4 
>  1 file changed, 4 insertions(+)
>
> diff --git a/src/mesa/drivers/dri/i965/intel_asm_annotation.c 
> b/src/mesa/drivers/dri/i965/intel_asm_annotation.c
> index 4717baf..d524725 100644
> --- a/src/mesa/drivers/dri/i965/intel_asm_annotation.c
> +++ b/src/mesa/drivers/dri/i965/intel_asm_annotation.c
> @@ -96,9 +96,13 @@ void annotate(struct brw_context *brw,
>struct backend_instruction *inst, unsigned offset)
>  {
> if (annotation->ann_size <= annotation->ann_count) {
> +  int old_size = annotation->ann_size;
>annotation->ann_size = MAX2(1024, annotation->ann_size * 2);
>annotation->ann = reralloc(annotation->mem_ctx, annotation->ann,
>   struct annotation, annotation->ann_size);
> +  memset(annotation->ann + old_size, 0,
> + (annotation->ann_size - old_size) * sizeof(struct annotation));
> +
>if (!annotation->ann)
>   return;
> }
> --
> 1.8.5.5
>
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] i965: Initialize new chunks of realloc'd memory.

2014-07-08 Thread Matt Turner
Otherwise we'd compare uninitialized pointers with NULL and dereference,
leading to crashes.
---
 src/mesa/drivers/dri/i965/intel_asm_annotation.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/intel_asm_annotation.c 
b/src/mesa/drivers/dri/i965/intel_asm_annotation.c
index 4717baf..d524725 100644
--- a/src/mesa/drivers/dri/i965/intel_asm_annotation.c
+++ b/src/mesa/drivers/dri/i965/intel_asm_annotation.c
@@ -96,9 +96,13 @@ void annotate(struct brw_context *brw,
   struct backend_instruction *inst, unsigned offset)
 {
if (annotation->ann_size <= annotation->ann_count) {
+  int old_size = annotation->ann_size;
   annotation->ann_size = MAX2(1024, annotation->ann_size * 2);
   annotation->ann = reralloc(annotation->mem_ctx, annotation->ann,
  struct annotation, annotation->ann_size);
+  memset(annotation->ann + old_size, 0,
+ (annotation->ann_size - old_size) * sizeof(struct annotation));
+
   if (!annotation->ann)
  return;
}
-- 
1.8.5.5

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev