Skip to content

Commit da943fe

Browse files
authored
Use uintptr_t for pointer arithmetic (#455)
1 parent a04486d commit da943fe

File tree

6 files changed

+23
-16
lines changed

6 files changed

+23
-16
lines changed

LICENSE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2006-2024 Stephen F. Booth
3+
Copyright (c) 2006-2025 Stephen F. Booth
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Sources/CSFBAudioEngine/Decoders/SFBDSDIFFDecoder.mm

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
//
2-
// Copyright (c) 2014-2024 Stephen F. Booth <[email protected]>
2+
// Copyright (c) 2014-2025 Stephen F. Booth <[email protected]>
33
// Part of https://github.com/sbooth/SFBAudioEngine
44
// MIT license
55
//
66

7+
#import <cstdint>
78
#import <map>
89
#import <memory>
910
#import <string>
@@ -870,7 +871,7 @@ - (BOOL)decodeIntoBuffer:(AVAudioCompressedBuffer *)buffer packetCount:(AVAudioP
870871
// Read interleaved input, grouped as 8 one bit samples per frame (a single channel byte) into
871872
// a clustered frame (one channel byte per channel)
872873

873-
uint8_t *buf = (uint8_t *)buffer.data + buffer.byteLength;
874+
auto buf = static_cast<uint8_t *>(reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(buffer.data) + buffer.byteLength));
874875
NSInteger bytesToRead = std::min(packetsToRead * packetSize, buffer.byteCapacity - buffer.byteLength);
875876

876877
NSInteger bytesRead;

Sources/CSFBAudioEngine/Decoders/SFBDSDPCMDecoder.mm

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//
2-
// Copyright (c) 2018-2024 Stephen F. Booth <[email protected]>
2+
// Copyright (c) 2018-2025 Stephen F. Booth <[email protected]>
33
// Part of https://github.com/sbooth/SFBAudioEngine
44
// MIT license
55
//
66

77
#import <algorithm>
8+
#import <cstdint>
89
#import <vector>
910

1011
#import <os/log.h>
@@ -483,7 +484,7 @@ - (BOOL)decodeIntoBuffer:(AVAudioPCMBuffer *)buffer frameLength:(AVAudioFrameCou
483484
AVAudioChannelCount channelCount = buffer.format.channelCount;
484485
bool isBigEndian = _buffer.format.streamDescription->mFormatFlags & kAudioFormatFlagIsBigEndian;
485486
for(AVAudioChannelCount channel = 0; channel < channelCount; ++channel) {
486-
const uint8_t *input = static_cast<const uint8_t *>(_buffer.data) + channel;
487+
const auto input = static_cast<const uint8_t *>(reinterpret_cast<const void *>(reinterpret_cast<uintptr_t>(_buffer.data) + channel));
487488
float *output = floatChannelData[channel];
488489
_context[channel].Translate(framesDecoded, input, channelCount, !isBigEndian, output, 1);
489490
// Boost signal by 6 dBFS

Sources/CSFBAudioEngine/Decoders/SFBDSFDecoder.m

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
//
2-
// Copyright (c) 2014-2024 Stephen F. Booth <[email protected]>
2+
// Copyright (c) 2014-2025 Stephen F. Booth <[email protected]>
33
// Part of https://github.com/sbooth/SFBAudioEngine
44
// MIT license
55
//
66

7+
@import stdint_h;
8+
79
@import os.log;
810

911
#import "SFBDSFDecoder.h"
@@ -344,7 +346,7 @@ - (BOOL)decodeIntoBuffer:(AVAudioCompressedBuffer *)buffer packetCount:(AVAudioP
344346

345347
// Copy data from the internal buffer to output
346348
uint32_t copySize = packetsToCopy * packetSize;
347-
memcpy((uint8_t *)buffer.data + (packetsToSkip * packetSize), _buffer.data, copySize);
349+
memcpy((void *)((uintptr_t)buffer.data + (packetsToSkip * packetSize)), _buffer.data, copySize);
348350
buffer.packetCount += packetsToCopy;
349351
buffer.byteLength += copySize;
350352

@@ -401,9 +403,8 @@ - (BOOL)seekToPacket:(AVAudioFramePosition)packet error:(NSError **)error
401403

402404
// Move data
403405
uint32_t packetSize = kSFBBytesPerDSDPacketPerChannel * _processingFormat.channelCount;
404-
uint8_t *dst = (uint8_t *)_buffer.data;
405-
const uint8_t *src = (uint8_t *)_buffer.data + (packetsToSkip * packetSize);
406-
memmove(dst, src, packetsToMove * packetSize);
406+
const void *src = (const void *)((uintptr_t)_buffer.data + (packetsToSkip * packetSize));
407+
memmove(_buffer.data, src, packetsToMove * packetSize);
407408

408409
_buffer.packetCount = packetsToMove;
409410
_buffer.byteLength = packetsToMove * packetSize;

Sources/CSFBAudioEngine/Decoders/SFBDoPDecoder.m

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
//
2-
// Copyright (c) 2014-2024 Stephen F. Booth <[email protected]>
2+
// Copyright (c) 2014-2025 Stephen F. Booth <[email protected]>
33
// Part of https://github.com/sbooth/SFBAudioEngine
44
// MIT license
55
//
66

7+
@import stdint_h;
8+
79
@import os.log;
810

911
@import AVFAudioExtensions;
@@ -228,8 +230,8 @@ - (BOOL)decodeIntoBuffer:(AVAudioPCMBuffer *)buffer frameLength:(AVAudioFrameCou
228230
uint8_t marker = _marker;
229231
AVAudioChannelCount channelCount = _processingFormat.channelCount;
230232
for(AVAudioChannelCount channel = 0; channel < channelCount; ++channel) {
231-
const uint8_t *input = (uint8_t *)_buffer.data + channel;
232-
uint8_t *output = (uint8_t *)buffer.audioBufferList->mBuffers[channel].mData + buffer.audioBufferList->mBuffers[channel].mDataByteSize;
233+
const uint8_t *input = (const void *)((uintptr_t)_buffer.data + channel);
234+
uint8_t *output = (void *)((uintptr_t)buffer.audioBufferList->mBuffers[channel].mData + buffer.audioBufferList->mBuffers[channel].mDataByteSize);
233235

234236
// The DoP marker should match across channels
235237
marker = _marker;

Sources/CSFBAudioEngine/Output/SFBBufferOutputSource.m

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
//
2-
// Copyright (c) 2010-2022 Stephen F. Booth <[email protected]>
2+
// Copyright (c) 2010-2025 Stephen F. Booth <[email protected]>
33
// Part of https://github.com/sbooth/SFBAudioEngine
44
// MIT license
55
//
66

7+
@import stdint_h;
8+
79
#import "SFBBufferOutputSource.h"
810

911
@interface SFBBufferOutputSource ()
@@ -59,7 +61,7 @@ - (BOOL)readBytes:(void *)buffer length:(NSInteger)length bytesRead:(NSInteger *
5961
}
6062

6163
size_t bytesToCopy = MIN(bytesAvailable, (size_t)length);
62-
memcpy(buffer, (uint8_t *)_buffer + _pos, bytesToCopy);
64+
memcpy(buffer, (const void *)((uintptr_t)_buffer + _pos), bytesToCopy);
6365
_pos += bytesToCopy;
6466
*bytesRead = (NSInteger)bytesToCopy;
6567

@@ -80,7 +82,7 @@ - (BOOL)writeBytes:(const void *)buffer length:(NSInteger)length bytesWritten:(N
8082
}
8183

8284
size_t bytesToCopy = MIN(remainingCapacity, (size_t)length);
83-
memcpy((uint8_t *)_buffer + _pos, buffer, bytesToCopy);
85+
memcpy((void *)((uintptr_t)_buffer + _pos), buffer, bytesToCopy);
8486
_pos += bytesToCopy;
8587
*bytesWritten = (NSInteger)bytesToCopy;
8688

0 commit comments

Comments
 (0)