/[rdesktop]/sourceforge.net/trunk/rdesktop/cache.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /sourceforge.net/trunk/rdesktop/cache.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 563 - (hide annotations)
Wed Dec 24 17:23:03 2003 UTC (20 years, 5 months ago) by jsorg71
File MIME type: text/plain
File size: 5045 byte(s)
fix seg fault when offset goes negative in desktop cache

1 matty 9 /*
2     rdesktop: A Remote Desktop Protocol client.
3     Cache routines
4 matthewc 207 Copyright (C) Matthew Chapman 1999-2002
5 matty 9
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10    
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     GNU General Public License for more details.
15    
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19     */
20    
21 matty 10 #include "rdesktop.h"
22 matty 9
23 matty 10 #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(array[0]))
24    
25    
26     /* BITMAP CACHE */
27 jsorg71 379 static HBITMAP g_bmpcache[3][600];
28 matty 10
29     /* Retrieve a bitmap from the cache */
30 matty 25 HBITMAP
31     cache_get_bitmap(uint8 cache_id, uint16 cache_idx)
32 matty 9 {
33     HBITMAP bitmap;
34    
35 jsorg71 379 if ((cache_id < NUM_ELEMENTS(g_bmpcache)) && (cache_idx < NUM_ELEMENTS(g_bmpcache[0])))
36 matty 9 {
37 jsorg71 379 bitmap = g_bmpcache[cache_id][cache_idx];
38 matty 9 if (bitmap != NULL)
39     return bitmap;
40     }
41    
42 matty 30 error("get bitmap %d:%d\n", cache_id, cache_idx);
43 matty 9 return NULL;
44     }
45    
46 matty 10 /* Store a bitmap in the cache */
47 matty 25 void
48     cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap)
49 matty 9 {
50     HBITMAP old;
51    
52 jsorg71 379 if ((cache_id < NUM_ELEMENTS(g_bmpcache)) && (cache_idx < NUM_ELEMENTS(g_bmpcache[0])))
53 matty 9 {
54 jsorg71 379 old = g_bmpcache[cache_id][cache_idx];
55 matty 9 if (old != NULL)
56 matty 10 ui_destroy_bitmap(old);
57 matty 9
58 jsorg71 379 g_bmpcache[cache_id][cache_idx] = bitmap;
59 matty 9 }
60     else
61     {
62 matty 30 error("put bitmap %d:%d\n", cache_id, cache_idx);
63 matty 9 }
64     }
65    
66 matty 10
67     /* FONT CACHE */
68 jsorg71 379 static FONTGLYPH g_fontcache[12][256];
69 matty 10
70     /* Retrieve a glyph from the font cache */
71 matty 25 FONTGLYPH *
72     cache_get_font(uint8 font, uint16 character)
73 matty 9 {
74 matty 10 FONTGLYPH *glyph;
75 matty 9
76 jsorg71 379 if ((font < NUM_ELEMENTS(g_fontcache)) && (character < NUM_ELEMENTS(g_fontcache[0])))
77 matty 9 {
78 jsorg71 379 glyph = &g_fontcache[font][character];
79 matty 9 if (glyph->pixmap != NULL)
80     return glyph;
81     }
82    
83 matty 30 error("get font %d:%d\n", font, character);
84 matty 9 return NULL;
85     }
86    
87 matty 10 /* Store a glyph in the font cache */
88 matty 25 void
89     cache_put_font(uint8 font, uint16 character, uint16 offset,
90     uint16 baseline, uint16 width, uint16 height, HGLYPH pixmap)
91 matty 9 {
92 matty 10 FONTGLYPH *glyph;
93 matty 9
94 jsorg71 379 if ((font < NUM_ELEMENTS(g_fontcache)) && (character < NUM_ELEMENTS(g_fontcache[0])))
95 matty 9 {
96 jsorg71 379 glyph = &g_fontcache[font][character];
97 matty 9 if (glyph->pixmap != NULL)
98 matty 10 ui_destroy_glyph(glyph->pixmap);
99 matty 9
100 matty 20 glyph->offset = offset;
101 matty 9 glyph->baseline = baseline;
102     glyph->width = width;
103     glyph->height = height;
104     glyph->pixmap = pixmap;
105     }
106     else
107     {
108 matty 30 error("put font %d:%d\n", font, character);
109 matty 9 }
110     }
111    
112 matty 10
113     /* TEXT CACHE */
114 jsorg71 379 static DATABLOB g_textcache[256];
115 matty 10
116     /* Retrieve a text item from the cache */
117 matty 25 DATABLOB *
118     cache_get_text(uint8 cache_id)
119 matty 9 {
120 matty 10 DATABLOB *text;
121 matty 9
122 jsorg71 379 if (cache_id < NUM_ELEMENTS(g_textcache))
123 matty 9 {
124 jsorg71 379 text = &g_textcache[cache_id];
125 matty 9 if (text->data != NULL)
126     return text;
127     }
128    
129 matty 30 error("get text %d\n", cache_id);
130 matty 9 return NULL;
131     }
132    
133 matty 10 /* Store a text item in the cache */
134 matty 25 void
135     cache_put_text(uint8 cache_id, void *data, int length)
136 matty 9 {
137 matty 10 DATABLOB *text;
138 matty 9
139 jsorg71 379 if (cache_id < NUM_ELEMENTS(g_textcache))
140 matty 9 {
141 jsorg71 379 text = &g_textcache[cache_id];
142 matty 9 if (text->data != NULL)
143 matty 10 xfree(text->data);
144 matty 9
145 matty 10 text->data = xmalloc(length);
146 matty 9 text->size = length;
147     memcpy(text->data, data, length);
148     }
149     else
150     {
151 matty 30 error("put text %d\n", cache_id);
152 matty 9 }
153     }
154 matty 10
155    
156     /* DESKTOP CACHE */
157 jsorg71 379 static uint8 g_deskcache[0x38400 * 4];
158 matty 10
159     /* Retrieve desktop data from the cache */
160 matty 25 uint8 *
161 matty 28 cache_get_desktop(uint32 offset, int cx, int cy, int bytes_per_pixel)
162 matty 10 {
163 matty 28 int length = cx * cy * bytes_per_pixel;
164 matty 16
165 jsorg71 563 if (offset > sizeof(g_deskcache))
166     offset = 0;
167    
168 jsorg71 379 if ((offset + length) <= sizeof(g_deskcache))
169 matty 10 {
170 jsorg71 379 return &g_deskcache[offset];
171 matty 10 }
172    
173 matty 30 error("get desktop %d:%d\n", offset, length);
174 matty 10 return NULL;
175     }
176    
177     /* Store desktop data in the cache */
178 matty 25 void
179 astrand 82 cache_put_desktop(uint32 offset, int cx, int cy, int scanline, int bytes_per_pixel, uint8 * data)
180 matty 10 {
181 matty 28 int length = cx * cy * bytes_per_pixel;
182 matty 16
183 jsorg71 563 if (offset > sizeof(g_deskcache))
184     offset = 0;
185    
186 jsorg71 379 if ((offset + length) <= sizeof(g_deskcache))
187 matty 10 {
188 matty 28 cx *= bytes_per_pixel;
189 matty 16 while (cy--)
190     {
191 jsorg71 379 memcpy(&g_deskcache[offset], data, cx);
192 matty 16 data += scanline;
193     offset += cx;
194     }
195 matty 10 }
196     else
197     {
198 matty 30 error("put desktop %d:%d\n", offset, length);
199 matty 10 }
200     }
201 matty 28
202    
203     /* CURSOR CACHE */
204 jsorg71 379 static HCURSOR g_cursorcache[0x20];
205 matty 28
206     /* Retrieve cursor from cache */
207 astrand 64 HCURSOR
208     cache_get_cursor(uint16 cache_idx)
209 matty 28 {
210     HCURSOR cursor;
211    
212 jsorg71 379 if (cache_idx < NUM_ELEMENTS(g_cursorcache))
213 matty 28 {
214 jsorg71 379 cursor = g_cursorcache[cache_idx];
215 matty 28 if (cursor != NULL)
216     return cursor;
217     }
218    
219 matty 30 error("get cursor %d\n", cache_idx);
220 matty 28 return NULL;
221     }
222    
223     /* Store cursor in cache */
224     void
225     cache_put_cursor(uint16 cache_idx, HCURSOR cursor)
226     {
227     HCURSOR old;
228    
229 jsorg71 379 if (cache_idx < NUM_ELEMENTS(g_cursorcache))
230 matty 28 {
231 jsorg71 379 old = g_cursorcache[cache_idx];
232 matty 28 if (old != NULL)
233     ui_destroy_cursor(old);
234    
235 jsorg71 379 g_cursorcache[cache_idx] = cursor;
236 matty 28 }
237     else
238     {
239 matty 30 error("put cursor %d\n", cache_idx);
240 matty 28 }
241     }

  ViewVC Help
Powered by ViewVC 1.1.26