Unsigned char[] is truncated

HI, I don’t understand where I’m wrong… here’s the code:

static void assignShapeToButton(const unsigned char shape[], ShapeButton& button)
{
    for (int i = 0; i < sizeof(shape); i++)
    {
        DBG(shape[i]);
    }
    Path p;
    p.loadPathFromData(shape, sizeof(shape));
    button.setShape(p, true, true, false);
}

//==============================================================================

static const unsigned char burgerMenuShapePath[]
    = { 110,109,0,0,128,64,0,0,32,65,108,0,0,224,65,0,0,32,65,98,254,212,232,65,0,0,32,65,0,0,240,65,252,
        169,17,65,0,0,240,65,0,0,0,65,98,0,0,240,65,8,172,220,64,254,212,232,65,0,0,192,64,0,0,224,65,0,0,
        192,64,108,0,0,128,64,0,0,192,64,98,16,88,57,64,0,0,192,64,0,0,0,64,8,172,220,64,0,0,0,64,0,0,0,65,
        98,0,0,0,64,252,169,17,65,16,88,57,64,0,0,32,65,0,0,128,64,0,0,32,65,99,109,0,0,224,65,0,0,96,65,108,
        0,0,128,64,0,0,96,65,98,16,88,57,64,0,0,96,65,0,0,0,64,4,86,110,65,0,0,0,64,0,0,128,65,98,0,0,0,64,
        254,212,136,65,16,88,57,64,0,0,144,65,0,0,128,64,0,0,144,65,108,0,0,224,65,0,0,144,65,98,254,212,232,
        65,0,0,144,65,0,0,240,65,254,212,136,65,0,0,240,65,0,0,128,65,98,0,0,240,65,4,86,110,65,254,212,232,
        65,0,0,96,65,0,0,224,65,0,0,96,65,99,109,0,0,224,65,0,0,176,65,108,0,0,128,64,0,0,176,65,98,16,88,57,
        64,0,0,176,65,0,0,0,64,2,43,183,65,0,0,0,64,0,0,192,65,98,0,0,0,64,254,212,200,65,16,88,57,64,0,0,208,
        65,0,0,128,64,0,0,208,65,108,0,0,224,65,0,0,208,65,98,254,212,232,65,0,0,208,65,0,0,240,65,254,212,
        200,65,0,0,240,65,0,0,192,65,98,0,0,240,65,2,43,183,65,254,212,232,65,0,0,176,65,0,0,224,65,0,0,176,
        65,99,101,0,0 };

calling assignShapeToButton(burgerMenuShapePath); this is what is printed in console:

8

110

109

0

0

128

64

0

0

Are taken in consideration only the first 8 char… why?

is a pointer… it does not contain any size information for the thing is it pointing to… either use a container that has a size (std::array, std::vector, etc) or pass in the size as well. sizeof(burgerMenuShapePath) will return the correct length, since it knows the actual data being referred to, so you can use that to pass in the length from the caller.

1 Like

Ok, thank you, I understand now, passing size_t and referring to it inside func makes everything goes well :pray:

1 Like