Lines 260-267
Link Here
|
260 |
delete mf; |
260 |
delete mf; |
261 |
return NULL; |
261 |
return NULL; |
262 |
} |
262 |
} |
263 |
|
263 |
guint32 word_off_size = (get_uint32(mf->begin()) + 1) * sizeof(guint32); |
264 |
gchar *p = mf->begin(); |
264 |
if (word_off_size >= cachestat.st_size || |
|
|
265 |
*(mf->begin() + cachestat.st_size - 1) != '\0') |
266 |
return NULL; |
267 |
|
268 |
gchar *p = mf->begin() + word_off_size; |
265 |
gboolean has_prefix; |
269 |
gboolean has_prefix; |
266 |
if (cachefiletype == CacheFileType_oft) |
270 |
if (cachefiletype == CacheFileType_oft) |
267 |
has_prefix = g_str_has_prefix(p, OFFSETFILE_MAGIC_DATA); |
271 |
has_prefix = g_str_has_prefix(p, OFFSETFILE_MAGIC_DATA); |
Lines 314-320
Link Here
|
314 |
} |
318 |
} |
315 |
g_free(tmpstr); |
319 |
g_free(tmpstr); |
316 |
} |
320 |
} |
317 |
if (cachestat.st_size!=glong(filedatasize + strlen(mf->begin()) +1)) { |
321 |
if (cachestat.st_size != static_cast<gulong>(filedatasize + sizeof(guint32) + strlen(mf->begin() + word_off_size) +1)) { |
318 |
delete mf; |
322 |
delete mf; |
319 |
return NULL; |
323 |
return NULL; |
320 |
} |
324 |
} |
Lines 375-381
Link Here
|
375 |
mf = get_cache_loadfile(oftfilename.c_str(), url, saveurl, cltfunc, filedatasize, 2); |
379 |
mf = get_cache_loadfile(oftfilename.c_str(), url, saveurl, cltfunc, filedatasize, 2); |
376 |
if (!mf) |
380 |
if (!mf) |
377 |
continue; |
381 |
continue; |
378 |
wordoffset = (guint32 *)(mf->begin()+strlen(mf->begin())+1); |
382 |
wordoffset = reinterpret_cast<guint32 *>(mf->begin()) + 1; |
379 |
return true; |
383 |
return true; |
380 |
} |
384 |
} |
381 |
return false; |
385 |
return false; |
Lines 425-431
Link Here
|
425 |
if (!mf.open(filename, oftstat.st_size)) { |
429 |
if (!mf.open(filename, oftstat.st_size)) { |
426 |
return fopen(filename, "wb"); |
430 |
return fopen(filename, "wb"); |
427 |
} |
431 |
} |
428 |
gchar *p = mf.begin(); |
432 |
guint32 word_off_size = (get_uint32(mf.begin()) + 1) * sizeof(guint32); |
|
|
433 |
if (word_off_size >= oftstat.st_size || |
434 |
*(mf.begin() + oftstat.st_size - 1) != '\0') |
435 |
return fopen(filename, "wb"); |
436 |
|
437 |
gchar *p = mf.begin() + word_off_size; |
429 |
bool has_prefix; |
438 |
bool has_prefix; |
430 |
if (cachefiletype == CacheFileType_oft) |
439 |
if (cachefiletype == CacheFileType_oft) |
431 |
has_prefix = g_str_has_prefix(p, OFFSETFILE_MAGIC_DATA); |
440 |
has_prefix = g_str_has_prefix(p, OFFSETFILE_MAGIC_DATA); |
Lines 506-511
Link Here
|
506 |
FILE *out= get_cache_savefile(oftfilename.c_str(), url, 2, cfilename, cltfunc); |
515 |
FILE *out= get_cache_savefile(oftfilename.c_str(), url, 2, cfilename, cltfunc); |
507 |
if (!out) |
516 |
if (!out) |
508 |
continue; |
517 |
continue; |
|
|
518 |
guint32 nentries = npages; |
519 |
fwrite(&nentries, sizeof(nentries), 1, out); |
520 |
fwrite(wordoffset, sizeof(guint32), npages, out); |
509 |
if (cachefiletype == CacheFileType_oft) |
521 |
if (cachefiletype == CacheFileType_oft) |
510 |
fwrite(OFFSETFILE_MAGIC_DATA, 1, sizeof(OFFSETFILE_MAGIC_DATA)-1, out); |
522 |
fwrite(OFFSETFILE_MAGIC_DATA, 1, sizeof(OFFSETFILE_MAGIC_DATA)-1, out); |
511 |
else |
523 |
else |
Lines 520-526
Link Here
|
520 |
#endif |
532 |
#endif |
521 |
} |
533 |
} |
522 |
fwrite("\n", 1, 2, out); |
534 |
fwrite("\n", 1, 2, out); |
523 |
fwrite(wordoffset, sizeof(guint32), npages, out); |
|
|
524 |
fclose(out); |
535 |
fclose(out); |
525 |
g_print("Save cache file: %s\n", cfilename.c_str()); |
536 |
g_print("Save cache file: %s\n", cfilename.c_str()); |
526 |
return true; |
537 |
return true; |