summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-01-22 09:37:31 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-01-22 21:05:30 +0000
commit8f1bbcf83e23286ebdfd17b83d886fc8f0a3eb2a (patch)
tree8b73a35a6104159f5055f1e0b42a63004758bc8f /toxcore
parente6c04ef0287a69c453f129778ef35932e0dff4b2 (diff)
Use <stdlib.h> for alloca on FreeBSD.
https://www.freebsd.org/cgi/man.cgi?alloca If stdlib.h does not define alloca, and we're using GCC (or Clang), we define the macro ourselves in terms of a GCC builtin.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/DHT.c4
-rw-r--r--toxcore/Messenger.c12
-rw-r--r--toxcore/Messenger.h4
-rw-r--r--toxcore/ccompat.h5
-rw-r--r--toxcore/network.c1
5 files changed, 24 insertions, 2 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 33ebc690..747f7328 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -535,7 +535,7 @@ int pack_nodes(uint8_t *data, uint16_t length, const Node_format *nodes, uint16_
535 memcpy(data + packed_length, nodes[i].public_key, CRYPTO_PUBLIC_KEY_SIZE); 535 memcpy(data + packed_length, nodes[i].public_key, CRYPTO_PUBLIC_KEY_SIZE);
536 packed_length += CRYPTO_PUBLIC_KEY_SIZE; 536 packed_length += CRYPTO_PUBLIC_KEY_SIZE;
537 537
538 uint32_t increment = ipp_size + CRYPTO_PUBLIC_KEY_SIZE; 538 const uint32_t increment = ipp_size + CRYPTO_PUBLIC_KEY_SIZE;
539 assert(increment == PACKED_NODE_SIZE_IP4 || increment == PACKED_NODE_SIZE_IP6); 539 assert(increment == PACKED_NODE_SIZE_IP4 || increment == PACKED_NODE_SIZE_IP6);
540 } 540 }
541 541
@@ -571,7 +571,7 @@ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed
571 len_processed += CRYPTO_PUBLIC_KEY_SIZE; 571 len_processed += CRYPTO_PUBLIC_KEY_SIZE;
572 ++num; 572 ++num;
573 573
574 uint32_t increment = ipp_size + CRYPTO_PUBLIC_KEY_SIZE; 574 const uint32_t increment = ipp_size + CRYPTO_PUBLIC_KEY_SIZE;
575 assert(increment == PACKED_NODE_SIZE_IP4 || increment == PACKED_NODE_SIZE_IP6); 575 assert(increment == PACKED_NODE_SIZE_IP4 || increment == PACKED_NODE_SIZE_IP6);
576 } 576 }
577 577
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 3cb0fbb6..bc7d055b 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -2258,10 +2258,14 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
2258 2258
2259 uint8_t filenumber = data[0]; 2259 uint8_t filenumber = data[0];
2260 2260
2261#if UINT8_MAX >= MAX_CONCURRENT_FILE_PIPES
2262
2261 if (filenumber >= MAX_CONCURRENT_FILE_PIPES) { 2263 if (filenumber >= MAX_CONCURRENT_FILE_PIPES) {
2262 break; 2264 break;
2263 } 2265 }
2264 2266
2267#endif
2268
2265 uint64_t filesize; 2269 uint64_t filesize;
2266 uint32_t file_type; 2270 uint32_t file_type;
2267 uint16_t filename_length = data_length - head_length; 2271 uint16_t filename_length = data_length - head_length;
@@ -2318,10 +2322,14 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
2318 uint8_t filenumber = data[1]; 2322 uint8_t filenumber = data[1];
2319 uint8_t control_type = data[2]; 2323 uint8_t control_type = data[2];
2320 2324
2325#if UINT8_MAX >= MAX_CONCURRENT_FILE_PIPES
2326
2321 if (filenumber >= MAX_CONCURRENT_FILE_PIPES) { 2327 if (filenumber >= MAX_CONCURRENT_FILE_PIPES) {
2322 break; 2328 break;
2323 } 2329 }
2324 2330
2331#endif
2332
2325 if (handle_filecontrol(m, i, send_receive, filenumber, control_type, data + 3, data_length - 3, userdata) == -1) { 2333 if (handle_filecontrol(m, i, send_receive, filenumber, control_type, data + 3, data_length - 3, userdata) == -1) {
2326 // TODO(iphydf): Do something different here? Right now, this 2334 // TODO(iphydf): Do something different here? Right now, this
2327 // check is pointless. 2335 // check is pointless.
@@ -2338,10 +2346,14 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
2338 2346
2339 uint8_t filenumber = data[0]; 2347 uint8_t filenumber = data[0];
2340 2348
2349#if UINT8_MAX >= MAX_CONCURRENT_FILE_PIPES
2350
2341 if (filenumber >= MAX_CONCURRENT_FILE_PIPES) { 2351 if (filenumber >= MAX_CONCURRENT_FILE_PIPES) {
2342 break; 2352 break;
2343 } 2353 }
2344 2354
2355#endif
2356
2345 struct File_Transfers *ft = &m->friendlist[i].file_receiving[filenumber]; 2357 struct File_Transfers *ft = &m->friendlist[i].file_receiving[filenumber];
2346 2358
2347 if (ft->status != FILESTATUS_TRANSFERRING) { 2359 if (ft->status != FILESTATUS_TRANSFERRING) {
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index a261a507..26977036 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -37,6 +37,10 @@
37/* This cannot be bigger than 256 */ 37/* This cannot be bigger than 256 */
38#define MAX_CONCURRENT_FILE_PIPES 256 38#define MAX_CONCURRENT_FILE_PIPES 256
39 39
40#if MAX_CONCURRENT_FILE_PIPES > UINT8_MAX + 1
41#error "uint8_t cannot represent all file transfer numbers"
42#endif
43
40 44
41#define FRIEND_ADDRESS_SIZE (CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint32_t) + sizeof(uint16_t)) 45#define FRIEND_ADDRESS_SIZE (CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint32_t) + sizeof(uint16_t))
42 46
diff --git a/toxcore/ccompat.h b/toxcore/ccompat.h
index e72e66ae..05212ec5 100644
--- a/toxcore/ccompat.h
+++ b/toxcore/ccompat.h
@@ -29,6 +29,11 @@
29// Emulation using alloca. 29// Emulation using alloca.
30#ifdef _WIN32 30#ifdef _WIN32
31#include <malloc.h> 31#include <malloc.h>
32#elif defined(__FreeBSD__)
33#include <stdlib.h>
34#if !defined(alloca) && defined(__GNUC__)
35#define alloca __builtin_alloca
36#endif
32#else 37#else
33#include <alloca.h> 38#include <alloca.h>
34#endif 39#endif
diff --git a/toxcore/network.c b/toxcore/network.c
index 7d6e415a..56f9aea0 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -31,6 +31,7 @@
31#endif 31#endif
32 32
33#if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_WINXP 33#if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_WINXP
34#undef _WIN32_WINNT
34#define _WIN32_WINNT 0x501 35#define _WIN32_WINNT 0x501
35#endif 36#endif
36 37