comparison mercurial/bdiff.c @ 15222:73015301db86

bdiff: fix pointer aliasing
author Matt Mackall <mpm@selenic.com>
date Tue, 11 Oct 2011 20:21:13 -0500
parents afe9269dccec
children eeac5e179243
comparison
equal deleted inserted replaced
15221:269374b89b74 15222:73015301db86
364 return rl ? rl : PyErr_NoMemory(); 364 return rl ? rl : PyErr_NoMemory();
365 } 365 }
366 366
367 static PyObject *bdiff(PyObject *self, PyObject *args) 367 static PyObject *bdiff(PyObject *self, PyObject *args)
368 { 368 {
369 char *sa, *sb; 369 char *sa, *sb, *rb;
370 PyObject *result = NULL; 370 PyObject *result = NULL;
371 struct line *al, *bl; 371 struct line *al, *bl;
372 struct hunk l, *h; 372 struct hunk l, *h;
373 char encode[12], *rb; 373 uint32_t encode[3];
374 int an, bn, len = 0, la, lb, count; 374 int an, bn, len = 0, la, lb, count;
375 375
376 if (!PyArg_ParseTuple(args, "s#s#:bdiff", &sa, &la, &sb, &lb)) 376 if (!PyArg_ParseTuple(args, "s#s#:bdiff", &sa, &la, &sb, &lb))
377 return NULL; 377 return NULL;
378 378
405 la = lb = 0; 405 la = lb = 0;
406 406
407 for (h = l.next; h; h = h->next) { 407 for (h = l.next; h; h = h->next) {
408 if (h->a1 != la || h->b1 != lb) { 408 if (h->a1 != la || h->b1 != lb) {
409 len = bl[h->b1].l - bl[lb].l; 409 len = bl[h->b1].l - bl[lb].l;
410 *(uint32_t *)(encode) = htonl(al[la].l - al->l); 410 encode[0] = htonl(al[la].l - al->l);
411 *(uint32_t *)(encode + 4) = htonl(al[h->a1].l - al->l); 411 encode[1] = htonl(al[h->a1].l - al->l);
412 *(uint32_t *)(encode + 8) = htonl(len); 412 encode[2] = htonl(len);
413 memcpy(rb, encode, 12); 413 memcpy(rb, encode, 12);
414 memcpy(rb + 12, bl[lb].l, len); 414 memcpy(rb + 12, bl[lb].l, len);
415 rb += 12 + len; 415 rb += 12 + len;
416 } 416 }
417 la = h->a2; 417 la = h->a2;