/* Reads a string from the #STRINGS section in the CHM file */
static LPCSTR GetChmString(CHMInfo *chm, DWORD offset)
{
+ LPCSTR str;
+
if(!chm->strings_stream)
return NULL;
if(chm->strings_size <= (offset >> BLOCK_BITS)) {
+ chm->strings_size = (offset >> BLOCK_BITS)+1;
if(chm->strings)
chm->strings = heap_realloc_zero(chm->strings,
- chm->strings_size = ((offset >> BLOCK_BITS)+1)*sizeof(char*));
+ chm->strings_size*sizeof(char*));
else
chm->strings = heap_alloc_zero(
- chm->strings_size = ((offset >> BLOCK_BITS)+1)*sizeof(char*));
+ chm->strings_size*sizeof(char*));
}
}
}
- return chm->strings[offset >> BLOCK_BITS] + (offset & BLOCK_MASK);
+ str = chm->strings[offset >> BLOCK_BITS] + (offset & BLOCK_MASK);
+ TRACE("offset %#x => %s\n", offset, debugstr_a(str));
+ return str;
}
static BOOL ReadChmSystem(CHMInfo *chm)
info->WinType.pszIndex = strdupW(null);
info->WinType.fsValidMembers=0;
info->WinType.fsWinProperties=HHWIN_PROP_TRI_PANE;
- info->WinType.pszCaption=strdupW(info->pCHMInfo->defTitle);
+ info->WinType.pszCaption=strdupW(info->pCHMInfo->defTitle ? info->pCHMInfo->defTitle : null);
info->WinType.dwStyles=WS_POPUP;
info->WinType.dwExStyles=0;
info->WinType.nShowState=SW_SHOW;
- info->WinType.pszFile=strdupW(info->pCHMInfo->defTopic);
+ info->WinType.pszFile=strdupW(info->pCHMInfo->defTopic ? info->pCHMInfo->defTopic : null);
info->WinType.curNavType=HHWIN_NAVTYPE_TOC;
return TRUE;
}
/* Opens the CHM file for reading */
CHMInfo *OpenCHM(LPCWSTR szFile)
{
- WCHAR file[MAX_PATH] = {0};
HRESULT hres;
+ CHMInfo *ret;
static const WCHAR wszSTRINGS[] = {'#','S','T','R','I','N','G','S',0};
- CHMInfo *ret = heap_alloc_zero(sizeof(CHMInfo));
+ if (!(ret = heap_alloc_zero(sizeof(CHMInfo))))
+ return NULL;
- GetFullPathNameW(szFile, sizeof(file)/sizeof(file[0]), file, NULL);
- ret->szFile = strdupW(file);
+ if (!(ret->szFile = strdupW(szFile))) {
+ heap_free(ret);
+ return NULL;
+ }
hres = CoCreateInstance(&CLSID_ITStorage, NULL, CLSCTX_INPROC_SERVER,
&IID_IITStorage, (void **) &ret->pITStorage) ;
WARN("Could not open storage: %08x\n", hres);
return CloseCHM(ret);
}
-
hres = IStorage_OpenStream(ret->pStorage, wszSTRINGS, NULL, STGM_READ, 0,
&ret->strings_stream);
if(FAILED(hres)) {
IStream_Release(chm->strings_stream);
if(chm->strings_size) {
- int i;
+ DWORD i;
for(i=0; i<chm->strings_size; i++)
heap_free(chm->strings[i]);
heap_free(chm->defTitle);
heap_free(chm->defTopic);
heap_free(chm->defToc);
+ heap_free(chm->szFile);
heap_free(chm);
return NULL;