Skip to content

Commit 4375bd1

Browse files
authored
Merge pull request #66 from jayhesselberth/asan-fixes
ASAN fixes for GNU-specific pointer arithmetic
2 parents 3b9eb39 + 9fa00bb commit 4375bd1

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

bwStats.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static struct vals_t *getVals(bigWigFile_t *fp, bwOverlapBlock_t *o, int i, uint
7070

7171
if(sz) {
7272
compressed = 1;
73-
buf = malloc(sz);
73+
buf = malloc(sz);
7474
}
7575
sz = 0; //This is now the size of the compressed buffer
7676

@@ -96,7 +96,7 @@ static struct vals_t *getVals(bigWigFile_t *fp, bwOverlapBlock_t *o, int i, uint
9696
}
9797

9898
p = buf;
99-
while(((uLongf) ((void*)p-buf)) < sz) {
99+
while(((uLongf) ((char*)p - (char*)buf)) < sz) {
100100
vtid = p[0];
101101
vstart = p[1];
102102
vend = p[2];

bwValues.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -524,15 +524,15 @@ bbOverlappingEntries_t *bbGetOverlappingEntriesCore(bigWigFile_t *fp, bwOverlapB
524524
tmp = o->size[i]; //TODO: Is this correct? Do non-gzipped bigBeds exist?
525525
}
526526

527-
bufEnd = buf + tmp;
527+
bufEnd = (char*)buf + tmp;
528528
while(buf < bufEnd) {
529529
entryTid = ((uint32_t*)buf)[0];
530530
start = ((uint32_t*)buf)[1];
531531
end = ((uint32_t*)buf)[2];
532-
buf += 12;
532+
buf = (char*)buf + 12;
533533
str = (char*)buf;
534534
slen = strlen(str) + 1;
535-
buf += slen;
535+
buf = (char*)buf + slen;
536536

537537
if(entryTid < tid) continue;
538538
if(entryTid > tid) break;
@@ -543,7 +543,7 @@ bbOverlappingEntries_t *bbGetOverlappingEntriesCore(bigWigFile_t *fp, bwOverlapB
543543
if(!pushBBIntervals(output, start, end, str, withString)) goto error;
544544
}
545545

546-
buf = bufEnd - tmp; //reset the buffer pointer
546+
buf = (char*)bufEnd - tmp; //reset the buffer pointer
547547
}
548548

549549
if(compressed && buf) free(buf);
@@ -552,7 +552,7 @@ bbOverlappingEntries_t *bbGetOverlappingEntriesCore(bigWigFile_t *fp, bwOverlapB
552552

553553
error:
554554
fprintf(stderr, "[bbGetOverlappingEntriesCore] Got an error\n");
555-
buf = bufEnd - tmp;
555+
buf = (char*)bufEnd - tmp;
556556
if(output) bbDestroyOverlappingEntries(output);
557557
if(compressed && buf) free(buf);
558558
if(compBuf) free(compBuf);

bwWrite.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,12 @@ static int flushBuffer(bigWigFile_t *fp) {
317317
if(!wb->ltype) return 0;
318318

319319
//Fill in the header
320-
if(!memcpy(wb->p, &(wb->tid), sizeof(uint32_t))) return 1;
321-
if(!memcpy(wb->p+4, &(wb->start), sizeof(uint32_t))) return 2;
322-
if(!memcpy(wb->p+8, &(wb->end), sizeof(uint32_t))) return 3;
323-
if(!memcpy(wb->p+12, &(wb->step), sizeof(uint32_t))) return 4;
324-
if(!memcpy(wb->p+16, &(wb->span), sizeof(uint32_t))) return 5;
325-
if(!memcpy(wb->p+20, &(wb->ltype), sizeof(uint8_t))) return 6;
320+
if(!memcpy((char*)wb->p, &(wb->tid), sizeof(uint32_t))) return 1;
321+
if(!memcpy((char*)wb->p+4, &(wb->start), sizeof(uint32_t))) return 2;
322+
if(!memcpy((char*)wb->p+8, &(wb->end), sizeof(uint32_t))) return 3;
323+
if(!memcpy((char*)wb->p+12, &(wb->step), sizeof(uint32_t))) return 4;
324+
if(!memcpy((char*)wb->p+16, &(wb->span), sizeof(uint32_t))) return 5;
325+
if(!memcpy((char*)wb->p+20, &(wb->ltype), sizeof(uint8_t))) return 6;
326326
//1 byte padding
327327
//Determine the number of items
328328
switch(wb->ltype) {
@@ -338,7 +338,7 @@ static int flushBuffer(bigWigFile_t *fp) {
338338
default:
339339
return 7;
340340
}
341-
if(!memcpy(wb->p+22, &nItems, sizeof(uint16_t))) return 8;
341+
if(!memcpy((char*)wb->p+22, &nItems, sizeof(uint16_t))) return 8;
342342

343343
if(sz) {
344344
//compress
@@ -399,9 +399,9 @@ int bwAddIntervals(bigWigFile_t *fp, const char* const* chrom, const uint32_t *s
399399
wb->span = 0;
400400
wb->step = 0;
401401
}
402-
if(!memcpy(wb->p+wb->l, start, sizeof(uint32_t))) return 7;
403-
if(!memcpy(wb->p+wb->l+4, end, sizeof(uint32_t))) return 8;
404-
if(!memcpy(wb->p+wb->l+8, values, sizeof(float))) return 9;
402+
if(!memcpy((char*)wb->p+wb->l, start, sizeof(uint32_t))) return 7;
403+
if(!memcpy((char*)wb->p+wb->l+4, end, sizeof(uint32_t))) return 8;
404+
if(!memcpy((char*)wb->p+wb->l+8, values, sizeof(float))) return 9;
405405
updateStats(fp, end[0]-start[0], values[0]);
406406
wb->l += 12;
407407

@@ -420,9 +420,9 @@ int bwAddIntervals(bigWigFile_t *fp, const char* const* chrom, const uint32_t *s
420420
flushBuffer(fp);
421421
wb->start = start[i];
422422
}
423-
if(!memcpy(wb->p+wb->l, &(start[i]), sizeof(uint32_t))) return 11;
424-
if(!memcpy(wb->p+wb->l+4, &(end[i]), sizeof(uint32_t))) return 12;
425-
if(!memcpy(wb->p+wb->l+8, &(values[i]), sizeof(float))) return 13;
423+
if(!memcpy((char*)wb->p+wb->l, &(start[i]), sizeof(uint32_t))) return 11;
424+
if(!memcpy((char*)wb->p+wb->l+4, &(end[i]), sizeof(uint32_t))) return 12;
425+
if(!memcpy((char*)wb->p+wb->l+8, &(values[i]), sizeof(float))) return 13;
426426
updateStats(fp, end[i]-start[i], values[i]);
427427
wb->l += 12;
428428
}
@@ -447,9 +447,9 @@ int bwAppendIntervals(bigWigFile_t *fp, const uint32_t *start, const uint32_t *e
447447
flushBuffer(fp);
448448
wb->start = start[i];
449449
}
450-
if(!memcpy(wb->p+wb->l, &(start[i]), sizeof(uint32_t))) return 4;
451-
if(!memcpy(wb->p+wb->l+4, &(end[i]), sizeof(uint32_t))) return 5;
452-
if(!memcpy(wb->p+wb->l+8, &(values[i]), sizeof(float))) return 6;
450+
if(!memcpy((char*)wb->p+wb->l, &(start[i]), sizeof(uint32_t))) return 4;
451+
if(!memcpy((char*)wb->p+wb->l+4, &(end[i]), sizeof(uint32_t))) return 5;
452+
if(!memcpy((char*)wb->p+wb->l+8, &(values[i]), sizeof(float))) return 6;
453453
updateStats(fp, end[i]-start[i], values[i]);
454454
wb->l += 12;
455455
}
@@ -482,8 +482,8 @@ int bwAddIntervalSpans(bigWigFile_t *fp, const char *chrom, const uint32_t *star
482482
flushBuffer(fp);
483483
wb->start = start[i];
484484
}
485-
if(!memcpy(wb->p+wb->l, &(start[i]), sizeof(uint32_t))) return 5;
486-
if(!memcpy(wb->p+wb->l+4, &(values[i]), sizeof(float))) return 6;
485+
if(!memcpy((char*)wb->p+wb->l, &(start[i]), sizeof(uint32_t))) return 5;
486+
if(!memcpy((char*)wb->p+wb->l+4, &(values[i]), sizeof(float))) return 6;
487487
updateStats(fp, span, values[i]);
488488
wb->l += 8;
489489
}
@@ -506,8 +506,8 @@ int bwAppendIntervalSpans(bigWigFile_t *fp, const uint32_t *start, const float *
506506
flushBuffer(fp);
507507
wb->start = start[i];
508508
}
509-
if(!memcpy(wb->p+wb->l, &(start[i]), sizeof(uint32_t))) return 4;
510-
if(!memcpy(wb->p+wb->l+4, &(values[i]), sizeof(float))) return 5;
509+
if(!memcpy((char*)wb->p+wb->l, &(start[i]), sizeof(uint32_t))) return 4;
510+
if(!memcpy((char*)wb->p+wb->l+4, &(values[i]), sizeof(float))) return 5;
511511
updateStats(fp, wb->span, values[i]);
512512
wb->l += 8;
513513
}
@@ -540,7 +540,7 @@ int bwAddIntervalSpanSteps(bigWigFile_t *fp, const char *chrom, uint32_t start,
540540
flushBuffer(fp);
541541
wb->start = wb->end;
542542
}
543-
if(!memcpy(wb->p+wb->l, &(values[i]), sizeof(float))) return 5;
543+
if(!memcpy((char*)wb->p+wb->l, &(values[i]), sizeof(float))) return 5;
544544
updateStats(fp, wb->span, values[i]);
545545
wb->l += 4;
546546
}
@@ -563,7 +563,7 @@ int bwAppendIntervalSpanSteps(bigWigFile_t *fp, const float *values, uint32_t n)
563563
flushBuffer(fp);
564564
wb->start = wb->end;
565565
}
566-
if(!memcpy(wb->p+wb->l, &(values[i]), sizeof(float))) return 4;
566+
if(!memcpy((char*)wb->p+wb->l, &(values[i]), sizeof(float))) return 4;
567567
updateStats(fp, wb->span, values[i]);
568568
wb->l += 4;
569569
}
@@ -754,7 +754,7 @@ int writeIndex(bigWigFile_t *fp) {
754754
}
755755
if(!root) return 4;
756756
fp->idx->root = root;
757-
757+
758758
ll = fp->writeBuffer->firstIndexNode;
759759
while(ll) {
760760
p = ll->next;
@@ -994,8 +994,8 @@ int addIntervalValue(bigWigFile_t *fp, uint64_t *nEntries, double *sum, double *
994994
newBuffer->p = calloc(itemsPerSlot, 32);
995995
if(!newBuffer->p) goto error;
996996
newBuffer->m = itemsPerSlot*32;
997-
memcpy(newBuffer->p, buffer->p+buffer->l-32, 4);
998-
memcpy(newBuffer->p+4, buffer->p+buffer->l-28, 4);
997+
memcpy(newBuffer->p, (unsigned char*)buffer->p+buffer->l-32, 4);
998+
memcpy((unsigned char*)newBuffer->p+4, (unsigned char*)buffer->p + buffer->l-28, 4);
999999
((uint32_t*) newBuffer->p)[2] = ((uint32_t*) newBuffer->p)[1] + zoom;
10001000
*sum = *sumsq = 0.0;
10011001
rv = updateInterval(fp, newBuffer, sum, sumsq, zoom, tid, start, end, value);
@@ -1122,7 +1122,7 @@ int writeZoomLevels(bigWigFile_t *fp) {
11221122
while(ll) {
11231123
p = ll->next;
11241124
free(ll);
1125-
ll=p;
1125+
ll=p;
11261126
}
11271127

11281128

0 commit comments

Comments
 (0)