aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llvocache.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:04 -0500
committerJacek Antonelli2008-08-15 23:45:04 -0500
commit117e22047c5752352342d64e3fb7ce00a4eb8113 (patch)
treee32de2cfba0dda8705ae528fcd1fbe23ba075685 /linden/indra/newview/llvocache.cpp
parentSecond Life viewer sources 1.18.0.6 (diff)
downloadmeta-impy-117e22047c5752352342d64e3fb7ce00a4eb8113.zip
meta-impy-117e22047c5752352342d64e3fb7ce00a4eb8113.tar.gz
meta-impy-117e22047c5752352342d64e3fb7ce00a4eb8113.tar.bz2
meta-impy-117e22047c5752352342d64e3fb7ce00a4eb8113.tar.xz
Second Life viewer sources 1.18.1.2
Diffstat (limited to 'linden/indra/newview/llvocache.cpp')
-rw-r--r--linden/indra/newview/llvocache.cpp45
1 files changed, 31 insertions, 14 deletions
diff --git a/linden/indra/newview/llvocache.cpp b/linden/indra/newview/llvocache.cpp
index f249c87..2b3569d 100644
--- a/linden/indra/newview/llvocache.cpp
+++ b/linden/indra/newview/llvocache.cpp
@@ -60,16 +60,25 @@ LLVOCacheEntry::LLVOCacheEntry()
60} 60}
61 61
62 62
63static inline void checkedRead(FILE *fp, void *data, size_t nbytes)
64{
65 if (fread(data, 1, nbytes, fp) != nbytes)
66 {
67 llwarns << "Short read" << llendl;
68 memset(data, 0, nbytes);
69 }
70}
71
63LLVOCacheEntry::LLVOCacheEntry(FILE *fp) 72LLVOCacheEntry::LLVOCacheEntry(FILE *fp)
64{ 73{
65 S32 size; 74 S32 size;
66 fread(&mLocalID, 1, sizeof(U32), fp); 75 checkedRead(fp, &mLocalID, sizeof(U32));
67 fread(&mCRC, 1, sizeof(U32), fp); 76 checkedRead(fp, &mCRC, sizeof(U32));
68 fread(&mHitCount, 1, sizeof(S32), fp); 77 checkedRead(fp, &mHitCount, sizeof(S32));
69 fread(&mDupeCount, 1, sizeof(S32), fp); 78 checkedRead(fp, &mDupeCount, sizeof(S32));
70 fread(&mCRCChangeCount, 1, sizeof(S32), fp); 79 checkedRead(fp, &mCRCChangeCount, sizeof(S32));
71 80
72 fread(&size, 1, sizeof(S32), fp); 81 checkedRead(fp, &size, sizeof(S32));
73 82
74 // Corruption in the cache entries 83 // Corruption in the cache entries
75 if ((size > 10000) || (size < 1)) 84 if ((size > 10000) || (size < 1))
@@ -85,7 +94,7 @@ LLVOCacheEntry::LLVOCacheEntry(FILE *fp)
85 } 94 }
86 95
87 mBuffer = new U8[size]; 96 mBuffer = new U8[size];
88 fread(mBuffer, 1, size, fp); 97 checkedRead(fp, mBuffer, size);
89 mDP.assignBuffer(mBuffer, size); 98 mDP.assignBuffer(mBuffer, size);
90} 99}
91 100
@@ -141,14 +150,22 @@ void LLVOCacheEntry::dump() const
141 << llendl; 150 << llendl;
142} 151}
143 152
153static inline void checkedWrite(FILE *fp, const void *data, size_t nbytes)
154{
155 if (fwrite(data, 1, nbytes, fp) != nbytes)
156 {
157 llwarns << "Short write" << llendl;
158 }
159}
160
144void LLVOCacheEntry::writeToFile(FILE *fp) const 161void LLVOCacheEntry::writeToFile(FILE *fp) const
145{ 162{
146 fwrite(&mLocalID, 1, sizeof(U32), fp); 163 checkedWrite(fp, &mLocalID, sizeof(U32));
147 fwrite(&mCRC, 1, sizeof(U32), fp); 164 checkedWrite(fp, &mCRC, sizeof(U32));
148 fwrite(&mHitCount, 1, sizeof(S32), fp); 165 checkedWrite(fp, &mHitCount, sizeof(S32));
149 fwrite(&mDupeCount, 1, sizeof(S32), fp); 166 checkedWrite(fp, &mDupeCount, sizeof(S32));
150 fwrite(&mCRCChangeCount, 1, sizeof(S32), fp); 167 checkedWrite(fp, &mCRCChangeCount, sizeof(S32));
151 S32 size = mDP.getBufferSize(); 168 S32 size = mDP.getBufferSize();
152 fwrite(&size, 1, sizeof(S32), fp); 169 checkedWrite(fp, &size, sizeof(S32));
153 fwrite(mBuffer, 1, size, fp); 170 checkedWrite(fp, mBuffer, size);
154} 171}