Changeset 199 for Evidence/Evidence.cc
- Timestamp:
- 04/20/10 16:01:16 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Evidence/Evidence.cc
r187 r199 240 240 char *Text; 241 241 242 // Safety check 243 if (Item->getSize() < 1) return NULL; 244 242 245 // Structure: print hex representation (3 characters per byte) 243 246 if (strlen(Item->getFormat()) != 1) { 244 if ((Text = (char *) malloc(3*Item->getSize()+1)) != NULL) { 245 for (int i=0; i<Item->getSize(); i++) sprintf(Text+3*i, "%02x", *((char *) Item->getData() + i)); 246 } 247 int Size = 3*Item->getSize()+1, N; 248 if ((Text = (char *) malloc(Size)) == NULL) return NULL; 249 250 char *CurrPos = Text; 251 for (int i=0; i<Item->getSize(); i++) { 252 N = snprintf(CurrPos, Size, "%02x ", *((char *) Item->getData() + i)); 253 if (N<0 || N>=Size) { 254 free(Text); 255 if (asprintf(&Text, "Structure length %d bytes, buffer overflow in ToString()", Item->getSize()) == -1) return NULL; 256 else return Text; 257 } 258 Size -= N; 259 CurrPos += N; 260 } 247 261 return Text; 248 262 }
Note:
See TracChangeset
for help on using the changeset viewer.