include/SDL_test_md5.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
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 
    22 /**
    23  *  \file SDL_test_md5.h
    24  *  
    25  *  Include file for SDL test framework.
    26  *
    27  *  This code is a part of the SDL2_test library, not the main SDL library.
    28  */
    29 
    30 /*
    31  ***********************************************************************
    32  ** Header file for implementation of MD5                             **
    33  ** RSA Data Security, Inc. MD5 Message-Digest Algorithm              **
    34  ** Created: 2/17/90 RLR                                              **
    35  ** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version               **
    36  ** Revised (for MD5): RLR 4/27/91                                    **
    37  **   -- G modified to have y&~z instead of y&z                       **
    38  **   -- FF, GG, HH modified to add in last register done             **
    39  **   -- Access pattern: round 2 works mod 5, round 3 works mod 3     **
    40  **   -- distinct additive constant for each step                     **
    41  **   -- round 4 added, working mod 7                                 **
    42  ***********************************************************************
    43 */
    44 
    45 /*
    46  ***********************************************************************
    47  **  Message-digest routines:                                         **
    48  **  To form the message digest for a message M                       **
    49  **    (1) Initialize a context buffer mdContext using MD5Init        **
    50  **    (2) Call MD5Update on mdContext and M                          **
    51  **    (3) Call MD5Final on mdContext                                 **
    52  **  The message digest is now in mdContext->digest[0...15]           **
    53  ***********************************************************************
    54 */
    55 
    56 #ifndef _SDL_test_md5_h
    57 #define _SDL_test_md5_h
    58 
    59 #include "begin_code.h"
    60 /* Set up for C function definitions, even when using C++ */
    61 #ifdef __cplusplus
    62 /* *INDENT-OFF* */
    63 extern "C" {
    64 /* *INDENT-ON* */
    65 #endif
    66 
    67 /* ------------ Definitions --------- */
    68 
    69 /* typedef a 32-bit type */
    70   typedef unsigned long int MD5UINT4;
    71 
    72 /* Data structure for MD5 (Message-Digest) computation */
    73   typedef struct {
    74     MD5UINT4  i[2];		/* number of _bits_ handled mod 2^64 */
    75     MD5UINT4  buf[4];		/* scratch buffer */
    76     unsigned char in[64];	/* input buffer */
    77     unsigned char digest[16];	/* actual digest after Md5Final call */
    78   } SDLTest_Md5Context;
    79 
    80 /* ---------- Function Prototypes ------------- */
    81 
    82 /** 
    83  * /brief initialize the context
    84  *
    85  * /param  mdContext		pointer to context variable
    86  *
    87  * Note: The function initializes the message-digest context
    88  *       mdContext. Call before each new use of the context - 
    89  *       all fields are set to zero.
    90  */
    91  void SDLTest_Md5Init(SDLTest_Md5Context * mdContext);
    92 
    93 
    94 /**
    95  * /brief update digest from variable length data
    96  * 
    97  * /param  mdContext       pointer to context variable
    98  * /param  inBuf           pointer to data array/string
    99  * /param  inLen           length of data array/string
   100  *
   101  * Note: The function updates the message-digest context to account 
   102  *       for the presence of each of the characters inBuf[0..inLen-1]
   103  *       in the message whose digest is being computed.
   104 */
   105 
   106  void SDLTest_Md5Update(SDLTest_Md5Context * mdContext, unsigned char *inBuf,
   107 				 unsigned int inLen);
   108 
   109 
   110 /*
   111  * /brief complete digest computation
   112  *
   113  * /param mdContext		pointer to context variable
   114  *
   115  * Note: The function terminates the message-digest computation and
   116  *       ends with the desired message digest in mdContext.digest[0..15].
   117  *       Always call before using the digest[] variable.
   118 */
   119 
   120  void SDLTest_Md5Final(SDLTest_Md5Context * mdContext);
   121 
   122 
   123 /* Ends C function definitions when using C++ */
   124 #ifdef __cplusplus
   125 /* *INDENT-OFF* */
   126 }
   127 /* *INDENT-ON* */
   128 #endif
   129 #include "close_code.h"
   130 
   131 #endif /* _SDL_test_md5_h */
   132 
   133 /* vi: set ts=4 sw=4 expandtab: */