Darwin haptic: Fixed a static analysis warning if axes==0.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
diff --git a/src/haptic/darwin/SDL_syshaptic.c b/src/haptic/darwin/SDL_syshaptic.c
index ff31cd4..4482682 100644
--- a/src/haptic/darwin/SDL_syshaptic.c
+++ b/src/haptic/darwin/SDL_syshaptic.c
@@ -771,18 +771,18 @@ static int
SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
{
int i;
- FFCONSTANTFORCE *constant;
- FFPERIODIC *periodic;
- FFCONDITION *condition; /* Actually an array of conditions - one per axis. */
- FFRAMPFORCE *ramp;
- FFCUSTOMFORCE *custom;
- FFENVELOPE *envelope;
- SDL_HapticConstant *hap_constant;
- SDL_HapticPeriodic *hap_periodic;
- SDL_HapticCondition *hap_condition;
- SDL_HapticRamp *hap_ramp;
- SDL_HapticCustom *hap_custom;
- DWORD *axes;
+ FFCONSTANTFORCE *constant = NULL;
+ FFPERIODIC *periodic = NULL;
+ FFCONDITION *condition = NULL; /* Actually an array of conditions - one per axis. */
+ FFRAMPFORCE *ramp = NULL;
+ FFCUSTOMFORCE *custom = NULL;
+ FFENVELOPE *envelope = NULL;
+ SDL_HapticConstant *hap_constant = NULL;
+ SDL_HapticPeriodic *hap_periodic = NULL;
+ SDL_HapticCondition *hap_condition = NULL;
+ SDL_HapticRamp *hap_ramp = NULL;
+ SDL_HapticCustom *hap_custom = NULL;
+ DWORD *axes = NULL;
/* Set global stuff. */
SDL_memset(dest, 0, sizeof(FFEFFECT));
@@ -911,26 +911,29 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
case SDL_HAPTIC_DAMPER:
case SDL_HAPTIC_INERTIA:
case SDL_HAPTIC_FRICTION:
- hap_condition = &src->condition;
- condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes);
- if (condition == NULL) {
- return SDL_OutOfMemory();
+ if (dest->cAxes > 0) {
+ hap_condition = &src->condition;
+ condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes);
+ if (condition == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(condition, 0, sizeof(FFCONDITION));
+
+ /* Specifics */
+ for (i = 0; i < dest->cAxes; i++) {
+ condition[i].lOffset = CONVERT(hap_condition->center[i]);
+ condition[i].lPositiveCoefficient =
+ CONVERT(hap_condition->right_coeff[i]);
+ condition[i].lNegativeCoefficient =
+ CONVERT(hap_condition->left_coeff[i]);
+ condition[i].dwPositiveSaturation =
+ CCONVERT(hap_condition->right_sat[i] / 2);
+ condition[i].dwNegativeSaturation =
+ CCONVERT(hap_condition->left_sat[i] / 2);
+ condition[i].lDeadBand = CCONVERT(hap_condition->deadband[i] / 2);
+ }
}
- SDL_memset(condition, 0, sizeof(FFCONDITION));
- /* Specifics */
- for (i = 0; i < dest->cAxes; i++) {
- condition[i].lOffset = CONVERT(hap_condition->center[i]);
- condition[i].lPositiveCoefficient =
- CONVERT(hap_condition->right_coeff[i]);
- condition[i].lNegativeCoefficient =
- CONVERT(hap_condition->left_coeff[i]);
- condition[i].dwPositiveSaturation =
- CCONVERT(hap_condition->right_sat[i] / 2);
- condition[i].dwNegativeSaturation =
- CCONVERT(hap_condition->left_sat[i] / 2);
- condition[i].lDeadBand = CCONVERT(hap_condition->deadband[i] / 2);
- }
dest->cbTypeSpecificParams = sizeof(FFCONDITION) * dest->cAxes;
dest->lpvTypeSpecificParams = condition;