Darwin haptic: Fixed a static analysis warning if axes==0.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 26 May 2015 12:47:03 -0400
changeset 9631e015da7884df
parent 9630 6c86d3216f6a
child 9632 6ae6b0b46e78
Darwin haptic: Fixed a static analysis warning if axes==0.
src/haptic/darwin/SDL_syshaptic.c
     1.1 --- a/src/haptic/darwin/SDL_syshaptic.c	Tue May 26 12:03:51 2015 -0400
     1.2 +++ b/src/haptic/darwin/SDL_syshaptic.c	Tue May 26 12:47:03 2015 -0400
     1.3 @@ -771,18 +771,18 @@
     1.4  SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
     1.5  {
     1.6      int i;
     1.7 -    FFCONSTANTFORCE *constant;
     1.8 -    FFPERIODIC *periodic;
     1.9 -    FFCONDITION *condition;     /* Actually an array of conditions - one per axis. */
    1.10 -    FFRAMPFORCE *ramp;
    1.11 -    FFCUSTOMFORCE *custom;
    1.12 -    FFENVELOPE *envelope;
    1.13 -    SDL_HapticConstant *hap_constant;
    1.14 -    SDL_HapticPeriodic *hap_periodic;
    1.15 -    SDL_HapticCondition *hap_condition;
    1.16 -    SDL_HapticRamp *hap_ramp;
    1.17 -    SDL_HapticCustom *hap_custom;
    1.18 -    DWORD *axes;
    1.19 +    FFCONSTANTFORCE *constant = NULL;
    1.20 +    FFPERIODIC *periodic = NULL;
    1.21 +    FFCONDITION *condition = NULL;     /* Actually an array of conditions - one per axis. */
    1.22 +    FFRAMPFORCE *ramp = NULL;
    1.23 +    FFCUSTOMFORCE *custom = NULL;
    1.24 +    FFENVELOPE *envelope = NULL;
    1.25 +    SDL_HapticConstant *hap_constant = NULL;
    1.26 +    SDL_HapticPeriodic *hap_periodic = NULL;
    1.27 +    SDL_HapticCondition *hap_condition = NULL;
    1.28 +    SDL_HapticRamp *hap_ramp = NULL;
    1.29 +    SDL_HapticCustom *hap_custom = NULL;
    1.30 +    DWORD *axes = NULL;
    1.31  
    1.32      /* Set global stuff. */
    1.33      SDL_memset(dest, 0, sizeof(FFEFFECT));
    1.34 @@ -911,26 +911,29 @@
    1.35      case SDL_HAPTIC_DAMPER:
    1.36      case SDL_HAPTIC_INERTIA:
    1.37      case SDL_HAPTIC_FRICTION:
    1.38 -        hap_condition = &src->condition;
    1.39 -        condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes);
    1.40 -        if (condition == NULL) {
    1.41 -            return SDL_OutOfMemory();
    1.42 +        if (dest->cAxes > 0) {
    1.43 +            hap_condition = &src->condition;
    1.44 +            condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes);
    1.45 +            if (condition == NULL) {
    1.46 +                return SDL_OutOfMemory();
    1.47 +            }
    1.48 +            SDL_memset(condition, 0, sizeof(FFCONDITION));
    1.49 +
    1.50 +            /* Specifics */
    1.51 +            for (i = 0; i < dest->cAxes; i++) {
    1.52 +                condition[i].lOffset = CONVERT(hap_condition->center[i]);
    1.53 +                condition[i].lPositiveCoefficient =
    1.54 +                    CONVERT(hap_condition->right_coeff[i]);
    1.55 +                condition[i].lNegativeCoefficient =
    1.56 +                    CONVERT(hap_condition->left_coeff[i]);
    1.57 +                condition[i].dwPositiveSaturation =
    1.58 +                    CCONVERT(hap_condition->right_sat[i] / 2);
    1.59 +                condition[i].dwNegativeSaturation =
    1.60 +                    CCONVERT(hap_condition->left_sat[i] / 2);
    1.61 +                condition[i].lDeadBand = CCONVERT(hap_condition->deadband[i] / 2);
    1.62 +            }
    1.63          }
    1.64 -        SDL_memset(condition, 0, sizeof(FFCONDITION));
    1.65  
    1.66 -        /* Specifics */
    1.67 -        for (i = 0; i < dest->cAxes; i++) {
    1.68 -            condition[i].lOffset = CONVERT(hap_condition->center[i]);
    1.69 -            condition[i].lPositiveCoefficient =
    1.70 -                CONVERT(hap_condition->right_coeff[i]);
    1.71 -            condition[i].lNegativeCoefficient =
    1.72 -                CONVERT(hap_condition->left_coeff[i]);
    1.73 -            condition[i].dwPositiveSaturation =
    1.74 -                CCONVERT(hap_condition->right_sat[i] / 2);
    1.75 -            condition[i].dwNegativeSaturation =
    1.76 -                CCONVERT(hap_condition->left_sat[i] / 2);
    1.77 -            condition[i].lDeadBand = CCONVERT(hap_condition->deadband[i] / 2);
    1.78 -        }
    1.79          dest->cbTypeSpecificParams = sizeof(FFCONDITION) * dest->cAxes;
    1.80          dest->lpvTypeSpecificParams = condition;
    1.81