src/audio/SDL_wave.h
author Sam Lantinga <slouken@libsdl.org>
Thu, 16 May 2013 00:43:22 -0700
changeset 7180 3733e68edbc3
parent 6885 700f1b25f77f
child 7191 75360622e65f
permissions -rw-r--r--
Fixed bug 1846 - _allmul implementation in SDL_stdlib.c doesn't clean up the stack

Colin Barrett

I see this manifest itself (VS2012 x86) as:

"Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."

in the first call to SDL_GetTicks in my application. The disassembly at the problem line is:

hires_now.QuadPart *= 1000;
00AD0792 push 0
00AD0794 push 3E8h
00AD0799 mov eax,dword ptr [ebp-10h]
00AD079C push eax
00AD079D mov ecx,dword ptr [hires_now]
00AD07A0 push ecx
00AD07A1 call _allmul (0AE7D40h)
00AD07A6 mov dword ptr [hires_now],eax
00AD07A9 mov dword ptr [ebp-10h],edx

Apparently _allmul should be popping the stack but isn't (other similar functions in SDL_stdlib.c - _alldiv and whatnot - DO pop the stack).

A 'ret 10h' at the end of _allmul appears to do the trick
slouken@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6885
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
slouken@0
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@0
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@0
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@0
    20
*/
slouken@1402
    21
#include "SDL_config.h"
slouken@0
    22
slouken@0
    23
/* WAVE files are little-endian */
slouken@0
    24
slouken@0
    25
/*******************************************/
slouken@0
    26
/* Define values for Microsoft WAVE format */
slouken@0
    27
/*******************************************/
slouken@1895
    28
#define RIFF		0x46464952      /* "RIFF" */
slouken@1895
    29
#define WAVE		0x45564157      /* "WAVE" */
slouken@1895
    30
#define FACT		0x74636166      /* "fact" */
slouken@1895
    31
#define LIST		0x5453494c      /* "LIST" */
slouken@1895
    32
#define FMT		0x20746D66      /* "fmt " */
slouken@1895
    33
#define DATA		0x61746164      /* "data" */
slouken@0
    34
#define PCM_CODE	0x0001
slouken@0
    35
#define MS_ADPCM_CODE	0x0002
icculus@1994
    36
#define IEEE_FLOAT_CODE	0x0003
slouken@0
    37
#define IMA_ADPCM_CODE	0x0011
slouken@1818
    38
#define MP3_CODE	0x0055
slouken@0
    39
#define WAVE_MONO	1
slouken@0
    40
#define WAVE_STEREO	2
slouken@0
    41
slouken@0
    42
/* Normally, these three chunks come consecutively in a WAVE file */
slouken@1895
    43
typedef struct WaveFMT
slouken@1895
    44
{
slouken@0
    45
/* Not saved in the chunk we read:
slouken@0
    46
	Uint32	FMTchunk;
slouken@0
    47
	Uint32	fmtlen;
slouken@0
    48
*/
slouken@1895
    49
    Uint16 encoding;
slouken@1895
    50
    Uint16 channels;            /* 1 = mono, 2 = stereo */
slouken@1895
    51
    Uint32 frequency;           /* One of 11025, 22050, or 44100 Hz */
slouken@1895
    52
    Uint32 byterate;            /* Average bytes per second */
slouken@1895
    53
    Uint16 blockalign;          /* Bytes per sample block */
slouken@1895
    54
    Uint16 bitspersample;       /* One of 8, 12, 16, or 4 for ADPCM */
slouken@0
    55
} WaveFMT;
slouken@0
    56
slouken@0
    57
/* The general chunk found in the WAVE file */
slouken@1895
    58
typedef struct Chunk
slouken@1895
    59
{
slouken@1895
    60
    Uint32 magic;
slouken@1895
    61
    Uint32 length;
slouken@1895
    62
    Uint8 *data;
slouken@0
    63
} Chunk;
slouken@1895
    64
/* vi: set ts=4 sw=4 expandtab: */