Skip to content

Commit

Permalink
Add support for compiling x86 version
Browse files Browse the repository at this point in the history
  • Loading branch information
thevindu-w committed Feb 14, 2025
1 parent c0bd4a5 commit 2797f44
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
clip_share
clip_share_no_ssl
clip_share_web
build/
build*
*.tar.*
*.tar
*.exe
Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ else
detected_OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
endif

ifeq ($(ARCH),x86)
BUILD_DIR:=$(BUILD_DIR)_x86
CFLAGS+= -m32
LDLIBS+= -m32
PROGRAM_NAME:=$(PROGRAM_NAME)32
PROGRAM_NAME_WEB:=$(PROGRAM_NAME_WEB)32
PROGRAM_NAME_NO_SSL:=$(PROGRAM_NAME_NO_SSL)32
endif

ifeq ($(detected_OS),Linux)
OBJS_C+= xclip/xclip.o xclip/xclib.o xscreenshot/xscreenshot.o
CFLAGS+= -ftree-vrp -Wformat-signedness -Wshift-overflow=2 -Wstringop-overflow=4 -Walloc-zero -Wduplicated-branches -Wduplicated-cond -Wtrampolines -Wjump-misses-init -Wlogical-op -Wvla-larger-than=65536
Expand Down Expand Up @@ -79,7 +88,7 @@ export LIBRARY_PATH=$(shell brew --prefix)/lib
else
$(error ClipShare is not supported on this platform!)
endif
LDLIBS=$(LDLIBS_SSL) $(LDLIBS_NO_SSL)
LDLIBS+= $(LDLIBS_SSL) $(LDLIBS_NO_SSL)
CFLAGS+= -DINFO_NAME=\"$(INFO_NAME)\" -DPROTOCOL_MIN=$(MIN_PROTO) -DPROTOCOL_MAX=$(MAX_PROTO)
CFLAGS_OPTIM+= -Werror

Expand Down
4 changes: 2 additions & 2 deletions src/servers/clip_share_web.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static void receiver_web(socket_t *sock) {
return;
}
} else if (!strcmp(method, "POST")) {
unsigned int len = 2048;
const unsigned int len = 2048;
char *headers = (char *)malloc(len);
*headers = 0;
int r = 0;
Expand All @@ -131,7 +131,7 @@ static void receiver_web(socket_t *sock) {
memcpy(ptr, buf, (size_t)r);
ptr += r;
*ptr = 0;
if (ptr - headers >= len - 256) break;
if ((size_t)(ptr - headers) >= len - 256) break;
cnt = 0;
} else if (cnt == 0) {
if (strstr(check, "\r\n\r\n")) break;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static inline void load_file(const char *file_name, data_buffer *buf_ptr) {
if (!file_name) error_exit("Error: invalid filename");
FILE *file_ptr = fopen(file_name, "rb");
if (!file_ptr) error_exit("Error: certificate file not found");
ssize_t len = get_file_size(file_ptr);
int64_t len = get_file_size(file_ptr);
if (len <= 0 || 65536L < len) {
fclose(file_ptr);
error_exit("Error: invalid certificate file size");
Expand Down
4 changes: 2 additions & 2 deletions src/utils/net_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ int read_sock(socket_t *socket, char *buf, uint64_t size) {
uint64_t read_req_sz = size - total_sz_read;
if (read_req_sz > 0x7FFFFFFFL) read_req_sz = 0x7FFFFFFFL; // prevent overflow due to casting
if (!IS_SSL(socket->type)) {
sz_read = _read_plain(socket->socket.plain, ptr, read_req_sz, &fatal);
sz_read = _read_plain(socket->socket.plain, ptr, (uint32_t)read_req_sz, &fatal);
#ifndef NO_SSL
} else {
sz_read = _read_SSL(socket->socket.ssl, ptr, (int)read_req_sz, &fatal);
Expand Down Expand Up @@ -708,7 +708,7 @@ int write_sock(socket_t *socket, const char *buf, uint64_t size) {
uint64_t write_req_sz = size - total_written;
if (write_req_sz > 0x7FFFFFFFL) write_req_sz = 0x7FFFFFFFL; // prevent overflow due to casting
if (!IS_SSL(socket->type)) {
sz_written = _write_plain(socket->socket.plain, ptr, write_req_sz, &fatal);
sz_written = _write_plain(socket->socket.plain, ptr, (uint32_t)write_req_sz, &fatal);
#ifndef NO_SSL
} else {
sz_written = _write_SSL(socket->socket.ssl, ptr, (int)write_req_sz, &fatal);
Expand Down
15 changes: 8 additions & 7 deletions src/utils/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,17 @@ int64_t get_file_size(FILE *fp) {

int is_directory(const char *path, int follow_symlinks) {
if (path[0] == 0) return 0; // empty path
struct stat sb;
int stat_result;
#if defined(__linux__) || defined(__APPLE__)
struct stat sb;
if (follow_symlinks) {
stat_result = stat(path, &sb);
} else {
stat_result = lstat(path, &sb);
}
#elif defined(_WIN32)
(void)follow_symlinks;
struct _stat64 sb;
wchar_t *wpath;
if (utf8_to_wchar_str(path, &wpath, NULL) != EXIT_SUCCESS) return 0;
stat_result = _wstat64(wpath, &sb);
Expand Down Expand Up @@ -226,7 +227,7 @@ void png_mem_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
* Returns 1 if conversion is needed and it will increase the length.
* Returns -1 if realloc failed.
*/
static inline int _realloc_for_crlf(char **str_p, uint64_t *len_p) {
static inline int _realloc_for_crlf(char **str_p, size_t *len_p) {
char *str = *str_p;
size_t increase = 0;
size_t ind;
Expand All @@ -240,8 +241,8 @@ static inline int _realloc_for_crlf(char **str_p, uint64_t *len_p) {
*len_p = ind;
return 0;
}
uint64_t req_len = ind + increase;
if (req_len >= 0xFFFFFFFFUL) {
size_t req_len = ind + increase;
if (req_len >= 0x7FFFFFFFUL || ind >= 0x7FFFFFFFUL) {
free(str);
error("realloc size too large");
return -1;
Expand All @@ -257,7 +258,7 @@ static inline int _realloc_for_crlf(char **str_p, uint64_t *len_p) {
return 1;
}

static inline void _convert_to_crlf(char *str, uint64_t new_len) {
static inline void _convert_to_crlf(char *str, size_t new_len) {
// converting to CRLF expands string. Therefore, start from the end to avoid overwriting
size_t new_ind = new_len - 1;
str[new_len] = 0; // terminating '\0'
Expand Down Expand Up @@ -298,7 +299,7 @@ int64_t convert_eol(char **str_p, int force_lf) {
if (force_lf) crlf = 0;
// realloc if available capacity is not enough
if (crlf) {
uint64_t new_len;
size_t new_len;
int status = _realloc_for_crlf(str_p, &new_len);
if (status == 0) return (int64_t)new_len; // no conversion needed
if (status < 0 || !*str_p) return -1; // realloc failed
Expand Down Expand Up @@ -682,7 +683,7 @@ static void _process_path(const wchar_t *path, list2 *lst, int depth, int includ
static void _recurse_dir(const wchar_t *_path, list2 *lst, int depth, int include_leaf_dirs);

static void _process_path(const wchar_t *path, list2 *lst, int depth, int include_leaf_dirs) {
struct stat sb;
struct _stat64 sb;
if (_wstat64(path, &sb) != 0) return;
if (S_ISDIR(sb.st_mode)) {
_recurse_dir(path, lst, depth + 1, include_leaf_dirs);
Expand Down

0 comments on commit 2797f44

Please sign in to comment.