Repository: libsdl-org/SDL
File: src/haptic/windows/SDL_dinputhaptic.c (C)

Code before:
    if (before->cAxes != after->cAxes) {
        return true;
    }
    // rglDirection must be non-null for DIEP_DIRECTION to be a valid flag
    if (after->rglDirection == NULL) {
        return false;
    }
    if (before->rglDirection == NULL) {
        return true;
    }

    return SDL_memcmp(before->rglDirection, after->rglDirection, sizeof(LONG) * before->cAxes) != 0;
}

BOOL DIGetEnvelopeUpdateFlag(DIEFFECT* before, DIEFFECT* after) {
    if (before->lpEnvelope == NULL && after->lpEnvelope == NULL) {
        return false;
    }
    // A null lpEnvelope is valid for DIEP_ENVELOPE (clears the envelope from the effect)
    if (before->lpEnvelope == NULL || after->lpEnvelope == NULL) {
        return true;
    }
    return SDL_memcmp(before->lpEnvelope, after->lpEnvelope, sizeof(DIENVELOPE)) != 0;
}

BOOL DIGetTypeSpecificParamsUpdateFlag(DIEFFECT* before, DIEFFECT* after)
{
    // Shouldn't happen since this implies an effect's type somehow changed, but need to check to avoid an out-of-bounds memcmp
    if (before->cbTypeSpecificParams != after->cbTypeSpecificParams) {
        return true;
    }
    // lpvTypeSpecificParams must be non-null for the DIEP_TYPESPECIFICPARAMS flag.
    if (after->lpvTypeSpecificParams == NULL) {
        return false;
    }
    if (before->lpvTypeSpecificParams == NULL) {
        return true;
    }
    return SDL_memcmp(before->lpvTypeSpecificParams, after->lpvTypeSpecificParams, before->cbTypeSpecificParams) != 0;
}

/*
    Calculate the exact flags needed when updating an existing DirectInput haptic effect.
*/
DWORD DICalculateUpdateFlags(DIEFFECT *before, DIEFFECT *after)
{
    DWORD flags = 0;

    if (DIGetDirectionUpdateFlag(before, after)) {
        flags |= DIEP_DIRECTION;
    }

Review comment (suggestion):
```suggestion
BOOL DIGetTypeSpecificParamsUpdateFlag(DIEFFECT *before, DIEFFECT *after)
```

Code after:
    if (before->cAxes != after->cAxes) {
        return true;
    }
    // rglDirection must be non-null for DIEP_DIRECTION to be a valid flag
    if (after->rglDirection == NULL) {
        return false;
    }
    if (before->rglDirection == NULL) {
        return true;
    }
    return SDL_memcmp(before->rglDirection, after->rglDirection, sizeof(LONG) * before->cAxes) != 0;
}

BOOL DIGetEnvelopeUpdateFlag(DIEFFECT* before, DIEFFECT* after)
{
    if (before->lpEnvelope == NULL && after->lpEnvelope == NULL) {
        return false;
    }
    // A null lpEnvelope is valid for DIEP_ENVELOPE (clears the envelope from the effect)
    if (before->lpEnvelope == NULL || after->lpEnvelope == NULL) {
        return true;
    }
    return SDL_memcmp(before->lpEnvelope, after->lpEnvelope, sizeof(DIENVELOPE)) != 0;
}

BOOL DIGetTypeSpecificParamsUpdateFlag(DIEFFECT *before, DIEFFECT *after)
{
    // Shouldn't happen since this implies an effect's type somehow changed, but need to check to avoid an out-of-bounds memcmp
    if (before->cbTypeSpecificParams != after->cbTypeSpecificParams) {
        return true;
    }
    // lpvTypeSpecificParams must be non-null for the DIEP_TYPESPECIFICPARAMS flag.
    if (after->lpvTypeSpecificParams == NULL) {
        return false;
    }
    if (before->lpvTypeSpecificParams == NULL) {
        return true;
    }
    return SDL_memcmp(before->lpvTypeSpecificParams, after->lpvTypeSpecificParams, before->cbTypeSpecificParams) != 0;
}

/*
    Calculate the exact flags needed when updating an existing DirectInput haptic effect.
*/
DWORD DICalculateUpdateFlags(DIEFFECT *before, DIEFFECT *after)
{
    DWORD flags = 0;

    if (DIGetDirectionUpdateFlag(before, after)) {
        flags |= DIEP_DIRECTION;
    }