comparison src/video/SDL_stretch.c @ 4543:d7cdc25af9a2 SDL-1.2

Better fix for bug 936
author Sam Lantinga <slouken@libsdl.org>
date Sun, 18 Jul 2010 10:28:57 -0700
parents abb56f7699ea
children
comparison
equal deleted inserted replaced
4541:abb56f7699ea 4543:d7cdc25af9a2
76 int status; 76 int status;
77 } last; 77 } last;
78 78
79 int i; 79 int i;
80 int pos, inc; 80 int pos, inc;
81 unsigned char *eip, *end; 81 unsigned char *eip, *fence;
82 unsigned char load, store; 82 unsigned char load, store;
83 83
84 /* See if we need to regenerate the copy buffer */ 84 /* See if we need to regenerate the copy buffer */
85 if ( (src_w == last.src_w) && 85 if ( (src_w == last.src_w) &&
86 (dst_w == last.dst_w) && (bpp == last.bpp) ) { 86 (dst_w == last.dst_w) && (bpp == last.bpp) ) {
113 } 113 }
114 #endif 114 #endif
115 pos = 0x10000; 115 pos = 0x10000;
116 inc = (src_w << 16) / dst_w; 116 inc = (src_w << 16) / dst_w;
117 eip = copy_row; 117 eip = copy_row;
118 end = copy_row+sizeof(copy_row); 118 fence = copy_row+sizeof(copy_row)-2;
119 for ( i=0; i<dst_w && eip < end; ++i ) { 119 for ( i=0; i<dst_w && eip < end; ++i ) {
120 while ( pos >= 0x10000L ) { 120 while ( pos >= 0x10000L ) {
121 if ( eip == fence ) {
122 return -1;
123 }
121 if ( bpp == 2 ) { 124 if ( bpp == 2 ) {
122 *eip++ = PREFIX16; 125 *eip++ = PREFIX16;
123 } 126 }
124 *eip++ = load; 127 *eip++ = load;
125 pos -= 0x10000L; 128 pos -= 0x10000L;
126 } 129 }
130 if ( eip == fence ) {
131 return -1;
132 }
127 if ( bpp == 2 ) { 133 if ( bpp == 2 ) {
128 *eip++ = PREFIX16; 134 *eip++ = PREFIX16;
129 } 135 }
130 *eip++ = store; 136 *eip++ = store;
131 pos += inc; 137 pos += inc;
132 } 138 }
133 *eip++ = RETURN; 139 *eip++ = RETURN;
134 140
135 /* Verify that we didn't overflow (too late!!!) */
136 if ( i < dst_w ) {
137 SDL_SetError("Copy buffer too small");
138 return(-1);
139 }
140 #ifdef HAVE_MPROTECT 141 #ifdef HAVE_MPROTECT
141 /* Make the code executable but not writeable */ 142 /* Make the code executable but not writeable */
142 if ( mprotect(copy_row, sizeof(copy_row), PROT_READ|PROT_EXEC) < 0 ) { 143 if ( mprotect(copy_row, sizeof(copy_row), PROT_READ|PROT_EXEC) < 0 ) {
143 SDL_SetError("Couldn't make copy buffer executable"); 144 SDL_SetError("Couldn't make copy buffer executable");
144 return(-1); 145 return(-1);