MarounMaroun 0 Light Poster

Hello all,
I have this code:

void SetMatrixRange(MyMatrix * matrix, int xfirst, int xlast,
        int yfirst, int ylast, int zfirst, int zlast, int value) {
    int i,j,k;
    for(i=xfirst;i<=xlast;i++)
        for(j=yfirst;j<=ylast;j++)
            for(k=zfirst;k<=zlast;k++)
                matrix->m[(i*ylast*zlast)+(j*zlast)+k]=value;
}

I allocated the matrix like this:

MyMatrix * CreateMyMatrix(int x, int y, int z) {
    MyMatrix *m_p=(MyMatrix *) malloc(sizeof (MyMatrix));
    if(m_p==NULL)
        return NULL;
    m_p->m=(int *)malloc(x*y*z*sizeof(int));
    if(m_p==NULL)
        return NULL;
    memset(m_p->m,0,x*y*z*sizeof(int));
    return m_p;
}

Now I want to change a sub-matrix in the 3D matrix.
I built this function:

void SetMatrixRange(MyMatrix * matrix, int xfirst, int xlast,
        int yfirst, int ylast, int zfirst, int zlast, int value) {
    int i,j,k;
    for(i=xfirst;i<=xlast;i++)
        for(j=yfirst;j<=ylast;j++)
            for(k=zfirst;k<=zlast;k++)
                matrix->m[(i*ylast*zlast)+(j*zlast)+k]=value;
}

But for some reason it doesn't change the value of the sub matrix as I wanted.

Any Ideas?