1
0
mirror of https://github.com/fumiama/simple-dict.git synced 2026-06-06 18:50:26 +08:00

remove warnings

This commit is contained in:
源文雨
2022-04-04 14:49:30 +08:00
parent 9e0b4ffc18
commit fdeb306c9b
5 changed files with 17 additions and 15 deletions

View File

@@ -3,7 +3,7 @@ project(simple-dict-server C)
SET(CMAKE_BUILD_TYPE "Release")
add_definitions(-DLISTEN_ON_IPV6)
# add_definitions(-DDEBUG)
add_definitions(-DDEBUG)
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
add_definitions("-DCPUBIT64")
ELSE()

View File

@@ -11,6 +11,7 @@
#include <arpa/inet.h>
#include <sys/stat.h>
#include <pthread.h>
#include <unistd.h>
#include "crypto.h"
#if !__APPLE__
@@ -83,7 +84,7 @@ void getMessage(void *p) {
} else {
offset += c;
#ifdef DEBUG
printf("[handle] Get %zd bytes, total: %zd.\n", c, offset);
printf("[handle] Get %d bytes, total: %d.\n", c, offset);
#endif
if(offset < CMDPACKET_HEAD_LEN) break;
if(offset < CMDPACKET_HEAD_LEN+cp->datalen) {
@@ -92,14 +93,14 @@ void getMessage(void *p) {
else {
offset += c;
#ifdef DEBUG
printf("[handle] Get %zd bytes, total: %zd.\n", c, offset);
printf("[handle] Get %d bytes, total: %d.\n", c, offset);
#endif
}
}
c = CMDPACKET_HEAD_LEN+cp->datalen; // 暂存 packet len
if(offset < c) break;
#ifdef DEBUG
printf("[handle] Decrypt %zd bytes data...\n", cp->datalen);
printf("[handle] Decrypt %d bytes data...\n", (int)cp->datalen);
#endif
if(cmdpacket_decrypt(cp, 0, pwd)) {
cp->data[cp->datalen] = 0;
@@ -119,7 +120,7 @@ void getMessage(void *p) {
c = 0;
} else offset = 0;
#ifdef DEBUG
printf("offset after analyzing packet: %zd\n", offset);
printf("offset after analyzing packet: %d\n", offset);
#endif
}
}

View File

@@ -162,7 +162,7 @@ int cmdpacket_decrypt(CMDPACKET* p, int index, const char pwd[64]) {
printf("decrypt md5: ");
for(int i = 0; i < 16; i++) printf("%02x", datamd5[i]);
putchar('\n');
printf("decrypted data len: %d, data: ", tout->len);
printf("decrypted data len: %u, data: ", (unsigned int)tout->len);
for(int i = 0; i < tout->len; i++) printf("%02x", tout->data[i]);
putchar('\n');
#endif

1
dict.c
View File

@@ -1,6 +1,7 @@
#include <stdio.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
#include <simplecrypto.h>
#include "dict.h"
#include "server.h"

View File

@@ -149,10 +149,10 @@ static int send_all(THREADTIMER *timer) {
if(buf) {
if(fread(buf, file_size, 1, fp) == 1) {
#ifdef DEBUG
printf("Get dict file size: %zu\n", file_size);
printf("Get dict file size: %u\n", (unsigned int)file_size);
#endif
char* encbuf = raw_encrypt(buf, &file_size, timer->index, cfg->pwd);
sprintf(timer->dat, "%zu$", file_size);
sprintf(timer->dat, "%u$", (unsigned int)file_size);
//printf("Get encrypted file size: %s\n", timer->dat);
//FILE* fp = fopen("raw_after_enc", "wb+");
//fwrite(encbuf, file_size, 1, fp);
@@ -181,11 +181,11 @@ static void init_dict_pool(FILE *fp) {
DICT* dnew = (DICT*)malloc(sizeof(DICT));
memcpy(dnew, d, sizeof(DICT));
char* digest = md5(d->key, strlen(d->key)+1);
char* digest = (char*)md5((uint8_t *)d->key, strlen(d->key)+1);
char* dp = digest;
int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ;
uint32_t c = 16-DICTPOOLSZ/8;
char* slot;
DICT* slot;
while((slot=dict_pool[p]) && c--) {
#ifdef DEBUG
@@ -214,7 +214,7 @@ static int s1_get(THREADTIMER *timer) {
int ch;
timer->lock_type = DICT_LOCK_SH;
char* digest = md5(timer->dat, strlen(timer->dat)+1);
char* digest = (char*)md5((uint8_t*)timer->dat, strlen(timer->dat)+1);
char* dp = digest;
int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ;
if(!dict_pool[p]) return close_and_send(timer, "null", 4);
@@ -246,7 +246,7 @@ static int s2_set(THREADTIMER *timer) {
if(fp) {
timer->lock_type = DICT_LOCK_EX;
char* digest = md5(timer->dat, strlen(timer->dat)+1);
char* digest = (char*)md5((uint8_t*)timer->dat, strlen(timer->dat)+1);
char* dp = digest;
int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ;
@@ -357,7 +357,7 @@ static int s4_del(THREADTIMER *timer) {
char ret[4];
timer->lock_type = DICT_LOCK_EX;
char* digest = md5(timer->dat, strlen(timer->dat)+1);
char* digest = (char*)md5((uint8_t*)timer->dat, strlen(timer->dat)+1);
char* dp = digest;
int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ;
uint32_t c = 16-DICTPOOLSZ/8;
@@ -395,7 +395,7 @@ static void accept_timer(void *p) {
while(accept_threads[index] && !pthread_kill(accept_threads[index], 0)) {
sleep(MAXWAITSEC / 4);
time_t waitsec = time(NULL) - timer->touch;
printf("Wait sec: %u, max: %u\n", waitsec, MAXWAITSEC);
printf("Wait sec: %u, max: %u\n", (unsigned int)waitsec, MAXWAITSEC);
if(waitsec > MAXWAITSEC) break;
}
puts("Call kill thread");
@@ -474,7 +474,7 @@ static void handle_accept(void *p) {
numbytes = CMDPACKET_HEAD_LEN+cp->datalen; // 暂存 packet len
if(offset < numbytes) break;
#ifdef DEBUG
printf("[handle] Decrypt %zd bytes data...\n", cp->datalen);
printf("[handle] Decrypt %d bytes data...\n", (int)cp->datalen);
#endif
if(cp->cmd < 5) {
if(cmdpacket_decrypt(cp, index, cfg->pwd)) {