Commit e9825018 authored by Olivier Fourdan's avatar Olivier Fourdan 🛠
Browse files

render: Fix build with gcc 12



The xserver fails to compile with the latest gcc 12:

 render/picture.c: In function ‘CreateSolidPicture’:
 render/picture.c:874:26: error: array subscript ‘union _SourcePict[0]’ is partly outside array bounds of ‘unsigned char[16]’ [-Werror=array-bounds]
  874 |     pPicture->pSourcePict->type = SourcePictTypeSolidFill;
      |                          ^~
 render/picture.c:868:45: note: object of size 16 allocated by ‘malloc’
  868 |     pPicture->pSourcePict = (SourcePictPtr) malloc(sizeof(PictSolidFill));
      |                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 render/picture.c: In function ‘CreateLinearGradientPicture’:
 render/picture.c:906:26: error: array subscript ‘union _SourcePict[0]’ is partly outside array bounds of ‘unsigned char[32]’ [-Werror=array-bounds]
  906 |     pPicture->pSourcePict->linear.type = SourcePictTypeLinear;
      |                          ^~
 render/picture.c:899:45: note: object of size 32 allocated by ‘malloc’
  899 |     pPicture->pSourcePict = (SourcePictPtr) malloc(sizeof(PictLinearGradient));
      |                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 render/picture.c: In function ‘CreateConicalGradientPicture’:
 render/picture.c:989:26: error: array subscript ‘union _SourcePict[0]’ is partly outside array bounds of ‘unsigned char[32]’ [-Werror=array-bounds]
  989 |     pPicture->pSourcePict->conical.type = SourcePictTypeConical;
      |                          ^~
 render/picture.c:982:45: note: object of size 32 allocated by ‘malloc’
  982 |     pPicture->pSourcePict = (SourcePictPtr) malloc(sizeof(PictConicalGradient));
      |                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 cc1: some warnings being treated as errors
 ninja: build stopped: subcommand failed.

This is because gcc 12 has become more strict and raises an warning now.

Fix the warning/error by allocating enough memory to store the union
struct.
Signed-off-by: Olivier Fourdan's avatarOlivier Fourdan <ofourdan@redhat.com>
Closes: xorg/xserver#1256
parent 22d58188
Pipeline #488179 passed with stages
in 2 minutes and 54 seconds
......@@ -865,7 +865,7 @@ CreateSolidPicture(Picture pid, xRenderColor * color, int *error)
}
pPicture->id = pid;
pPicture->pSourcePict = (SourcePictPtr) malloc(sizeof(PictSolidFill));
pPicture->pSourcePict = (SourcePictPtr) malloc(sizeof(SourcePict));
if (!pPicture->pSourcePict) {
*error = BadAlloc;
free(pPicture);
......@@ -896,7 +896,7 @@ CreateLinearGradientPicture(Picture pid, xPointFixed * p1, xPointFixed * p2,
}
pPicture->id = pid;
pPicture->pSourcePict = (SourcePictPtr) malloc(sizeof(PictLinearGradient));
pPicture->pSourcePict = (SourcePictPtr) malloc(sizeof(SourcePict));
if (!pPicture->pSourcePict) {
*error = BadAlloc;
free(pPicture);
......@@ -936,7 +936,7 @@ CreateRadialGradientPicture(Picture pid, xPointFixed * inner,
}
pPicture->id = pid;
pPicture->pSourcePict = (SourcePictPtr) malloc(sizeof(PictRadialGradient));
pPicture->pSourcePict = (SourcePictPtr) malloc(sizeof(SourcePict));
if (!pPicture->pSourcePict) {
*error = BadAlloc;
free(pPicture);
......@@ -979,7 +979,7 @@ CreateConicalGradientPicture(Picture pid, xPointFixed * center, xFixed angle,
}
pPicture->id = pid;
pPicture->pSourcePict = (SourcePictPtr) malloc(sizeof(PictConicalGradient));
pPicture->pSourcePict = (SourcePictPtr) malloc(sizeof(SourcePict));
if (!pPicture->pSourcePict) {
*error = BadAlloc;
free(pPicture);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment