comparison mercurial/mpatch.c @ 16437:d126a0d16856

util.h: replace ntohl/htonl with get/putbe32
author Matt Mackall <mpm@selenic.com>
date Mon, 16 Apr 2012 11:26:00 -0500
parents e501f45b0eba
children 923bd97b86a0
comparison
equal deleted inserted replaced
16436:e98460f6089d 16437:d126a0d16856
200 static struct flist *decode(const char *bin, int len) 200 static struct flist *decode(const char *bin, int len)
201 { 201 {
202 struct flist *l; 202 struct flist *l;
203 struct frag *lt; 203 struct frag *lt;
204 const char *data = bin + 12, *end = bin + len; 204 const char *data = bin + 12, *end = bin + len;
205 uint32_t decode[3]; /* for dealing with alignment issues */
206 205
207 /* assume worst case size, we won't have many of these lists */ 206 /* assume worst case size, we won't have many of these lists */
208 l = lalloc(len / 12); 207 l = lalloc(len / 12);
209 if (!l) 208 if (!l)
210 return NULL; 209 return NULL;
211 210
212 lt = l->tail; 211 lt = l->tail;
213 212
214 while (data <= end) { 213 while (data <= end) {
215 memcpy(decode, bin, 12); 214 lt->start = getbe32(bin);
216 lt->start = ntohl(decode[0]); 215 lt->end = getbe32(bin + 4);
217 lt->end = ntohl(decode[1]); 216 lt->len = getbe32(bin + 8);
218 lt->len = ntohl(decode[2]);
219 if (lt->start > lt->end) 217 if (lt->start > lt->end)
220 break; /* sanity check */ 218 break; /* sanity check */
221 bin = data + lt->len; 219 bin = data + lt->len;
222 if (bin < data) 220 if (bin < data)
223 break; /* big data + big (bogus) len can wrap around */ 221 break; /* big data + big (bogus) len can wrap around */
359 patchedsize(PyObject *self, PyObject *args) 357 patchedsize(PyObject *self, PyObject *args)
360 { 358 {
361 long orig, start, end, len, outlen = 0, last = 0; 359 long orig, start, end, len, outlen = 0, last = 0;
362 int patchlen; 360 int patchlen;
363 char *bin, *binend, *data; 361 char *bin, *binend, *data;
364 uint32_t decode[3]; /* for dealing with alignment issues */
365 362
366 if (!PyArg_ParseTuple(args, "ls#", &orig, &bin, &patchlen)) 363 if (!PyArg_ParseTuple(args, "ls#", &orig, &bin, &patchlen))
367 return NULL; 364 return NULL;
368 365
369 binend = bin + patchlen; 366 binend = bin + patchlen;
370 data = bin + 12; 367 data = bin + 12;
371 368
372 while (data <= binend) { 369 while (data <= binend) {
373 memcpy(decode, bin, 12); 370 start = getbe32(bin);
374 start = ntohl(decode[0]); 371 end = getbe32(bin + 4);
375 end = ntohl(decode[1]); 372 len = getbe32(bin + 8);
376 len = ntohl(decode[2]);
377 if (start > end) 373 if (start > end)
378 break; /* sanity check */ 374 break; /* sanity check */
379 bin = data + len; 375 bin = data + len;
380 if (bin < data) 376 if (bin < data)
381 break; /* big data + big (bogus) len can wrap around */ 377 break; /* big data + big (bogus) len can wrap around */