MCPcopy Create free account
hub / github.com/TASEmulators/fceux / loadDebuggerPreferences

Function loadDebuggerPreferences

src/drivers/win/pref.cpp:250–353  ·  view source on GitHub ↗

* Loads debugger preferences from a file * * @param f File to write the preferences to * @return 0 if everything went fine. An error code if something went wrong. **/

Source from the content-addressed store, hash-verified

248* @return 0 if everything went fine. An error code if something went wrong.
249**/
250int loadDebuggerPreferences(FILE* f)
251{
252 unsigned int i, size, len;
253 uint8 tmp;
254
255 // Read the number of CPU bookmarks
256 if (fread(&size, sizeof(unsigned int), 1, f) != 1) return 1;
257 // If there's more than 65536 bookmarks (bookmarking every address in the whole 16-bit address space), we're probably reading a corrupt file
258 if (size > 65536) return 1;
259
260 bookmarks.resize(size);
261 // Read the data of those bookmarks
262 char buffer[256];
263 for (i = 0; i < (int)size; ++i)
264 {
265 if (fread(&bookmarks[i].first, sizeof(unsigned int), 1, f) != 1) return 1;
266 if (fread(&len, sizeof(unsigned int), 1, f) != 1) return 1;
267 if (len >= 256) return 1;
268 if (fread(&buffer, 1, len, f) != len) return 1;
269 buffer[len] = 0;
270 bookmarks[i].second = buffer;
271 }
272
273 myNumWPs = 0;
274 // Ugetab:
275 // This took far too long to figure out...
276 // Nullifying the data is better than using free(), because
277 // a simple if(watchpoint[i].cond) can still evaluate to true.
278 // This causes several tests to fail, one of which kills
279 // conditional text loading when reusing a used condText.
280 for (i=0;i<65;i++)
281 {
282 watchpoint[i].cond = 0;
283 watchpoint[i].condText = 0;
284 watchpoint[i].desc = 0;
285 }
286
287 // Read the breakpoints
288 for (i=0;i<65;i++)
289 {
290 unsigned int len;
291
292 // Read the start address of the BP
293 if (fread(&watchpoint[myNumWPs].address, sizeof(watchpoint[myNumWPs].address), 1, f) != 1) return 1;
294 // Read the end address of the BP
295 if (fread(&watchpoint[myNumWPs].endaddress, sizeof(watchpoint[myNumWPs].endaddress), 1, f) != 1) return 1;
296 // Read the flags of the BP
297 if (fread(&watchpoint[myNumWPs].flags, sizeof(watchpoint[myNumWPs].flags), 1, f) != 1) return 1;
298
299 // Read the length of the BP condition
300 if (fread(&len, sizeof(len), 1, f) != 1) return 1;
301 // Windows enforces 32767 max characters for a textbox by default, if it exceeds that, it's probably a corrupt file
302 if (len > 32767) return 1;
303
304 // Delete eventual older conditions
305 if (watchpoint[myNumWPs].condText)
306 free(watchpoint[myNumWPs].condText);
307

Callers 1

loadPreferencesFunction · 0.85

Calls 1

checkConditionFunction · 0.85

Tested by

no test coverage detected