Skip to content

Commit

Permalink
several segfaults fixed; thanks to icculus for debugging help.
Browse files Browse the repository at this point in the history
  • Loading branch information
vogon committed Oct 23, 2002
1 parent c7c6aad commit 3efeba4
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 105 deletions.
15 changes: 11 additions & 4 deletions libinews/Makefile
@@ -1,7 +1,7 @@
CC = gcc-3.2
LN = ln
BASE_CFLAGS = -std=c99 -fPIC -ggdb -D_REENTRANT
BASE_LDFLAGS = -ggdb -fPIC -shared -lpthread
BASE_CFLAGS = -std=c99 -ggdb -fPIC -DPIC -D_REENTRANT
BASE_LDFLAGS = -ggdb -fPIC -DPIC -shared -lpthread

.c.o:
$(CC) $(BASE_CFLAGS) $(CFLAGS) -c $<
Expand All @@ -10,10 +10,17 @@ libinews.so.0: net.o utility.o init.o IList.o
$(CC) $(BASE_LDFLAGS) $(LDFLAGS) -o libinews.so.0 IList.o utility.o net.o init.o
$(LN) -sf libinews.so.0 libinews.so

libinews.a: net.o utility.o init.o IList.o
$(AR) cru libinews.a net.o utility.o init.o IList.o

test: libinews.so.0 test.c
$(CC) -ggdb -L. -linews -o test test.c

test-static: libinews.a test.c
$(CC) -ggdb -o test.o -c test.c
$(CC) -lpthread -ggdb $(LDFLAGS) -o test-static test.o libinews.a

clean:
rm -f *.o *.so *.so.0 test
rm -f *.o *.so *.a *.so.0 test test-static

all: libinews.so.0
all: libinews.so.0 libinews.a
4 changes: 3 additions & 1 deletion libinews/internals.h
Expand Up @@ -103,7 +103,9 @@ Sint8 __read_line(char *str, int max_sz);
Sint8 __write_block(char *str);
char *__chop(char *str);
void *__nop_thread(void *foo);
void __free_queue_info_list_element(/*G*/IList *ptr);
void __free_queue_info_list_element(IList *ptr);
ArticleInfo *__get_article_cache_ptr(Uint32 qid, Uint32 aid);
void __print_protocol_fuckery_message();
ArticleInfo *__copy_articleinfo(ArticleInfo *ptr);

#endif
57 changes: 32 additions & 25 deletions libinews/net.c
Expand Up @@ -26,22 +26,22 @@
#include <unistd.h>

/* don't like gotos? deal. I don't like duplicating code. */
#define FUNC_END(__success, __failure) { \
int __i; \
end_success: \
__i = 0; \
__inews_errno = (__inews_errno == \
ERR_STORYTOOLONG) ?\
ERR_STORYTOOLONG : \
ERR_SUCCESS; \
goto real_end; \
end_failure: \
__i = 1; \
real_end: \
pthread_mutex_trylock(&net_mutex); \
pthread_mutex_unlock(&net_mutex); \
return __i ? __failure : __success; \
}
#define FUNC_END(__success, __failure) { \
int __i; \
end_success: \
__i = 0; \
__inews_errno = (__inews_errno == \
ERR_STORYTOOLONG) ? \
ERR_STORYTOOLONG : \
ERR_SUCCESS; \
goto real_end; \
end_failure: \
__i = 1; \
real_end: \
pthread_mutex_trylock(&net_mutex); \
pthread_mutex_unlock(&net_mutex); \
return __i ? __failure : __success; \
}

Sint8 INEWS_connect(const char *hostname, Uint32 port) {
struct hostent *hostents;
Expand Down Expand Up @@ -334,20 +334,20 @@ ArticleInfo **INEWS_digest(int offset, int n) {
* article ID, and that there are no gaps in the cache. */

for (IList *ptr = digestcache; ptr; ptr = ilist_next(ptr)) {
ArticleInfo *tempptr = (ArticleInfo *)malloc(sizeof(ArticleInfo));
ArticleInfo *tempptr;
ArticleLinkedListHeader *curdata = ((ArticleLinkedListHeader *)(ptr->data));
if (curdata->qid == INEWS_getQID())
for (IList *aptr = curdata->head; aptr; aptr = ilist_next(aptr) && count < n) {
for (IList *aptr = curdata->head; aptr && (count < n); aptr = ilist_next(aptr)) {
if (requested_offset) {
if (((ArticleInfo *)(aptr->data))->aid < requested_offset) {
memcpy(tempptr, aptr->data, sizeof(ArticleInfo));
tempptr = __copy_articleinfo((ArticleInfo *)aptr->data);
retval[count++] = tempptr;
if (((ArticleInfo *)(aptr->data))->aid < offset) {
offset = ((ArticleInfo *)(aptr->data))->aid;
}
}
} else {
memcpy(tempptr, aptr->data, sizeof(ArticleInfo));
tempptr = __copy_articleinfo((ArticleInfo *)aptr->data);
retval[count++] = tempptr;
offset = ((ArticleInfo *)(aptr->data))->aid;
}
Expand All @@ -370,7 +370,7 @@ ArticleInfo **INEWS_digest(int offset, int n) {
goto end_failure;
}

while (count <= n) {
while (1) {
tempinfo = (ArticleInfo *)malloc(sizeof(ArticleInfo));
cacheptr = (ArticleInfo *)malloc(sizeof(ArticleInfo));

Expand Down Expand Up @@ -428,12 +428,12 @@ ArticleInfo **INEWS_digest(int offset, int n) {
IList *ptr;
ArticleLinkedListHeader *thisqueue;

for (ptr = digestcache; ptr; ptr = ilist_next(ptr)) {
for (ptr = digestcache; ptr; ptr = ilist_next(ptr)) {
if (((ArticleLinkedListHeader *)(ptr->data))->qid == INEWS_getQID()) break;
thisqueue = ((ArticleLinkedListHeader *)(ptr->data));
}

if (!ptr) {
if (!ptr) {
thisqueue = (ArticleLinkedListHeader *)malloc(sizeof(ArticleLinkedListHeader));
thisqueue->qid = INEWS_getQID();
thisqueue->head = NULL;
Expand All @@ -446,8 +446,7 @@ ArticleInfo **INEWS_digest(int offset, int n) {

/* if we hit a premature end-of-record, then we'll need to shrink down our
* return to prevent problems when we try to free it */
retval = (ArticleInfo **)realloc(retval, ((count+1) * sizeof(ArticleInfo *)));
retval[count] = NULL;
retval = (ArticleInfo **)realloc(retval, (count * sizeof(ArticleInfo *)));

goto end_success;

Expand Down Expand Up @@ -558,6 +557,9 @@ Sint8 INEWS_changeApprovalStatus(Uint32 aid, bool approve) {
}

artinfo = INEWS_digest(aid + 1, 1);

printf("artinfo[0] is %x\n", artinfo[0]);

if (artinfo[0]->approved == approve) {
INEWS_freeDigest(artinfo);
goto end_success;
Expand Down Expand Up @@ -589,6 +591,7 @@ Sint8 INEWS_changeApprovalStatus(Uint32 aid, bool approve) {
switch(tempstring[0]) {
case '+':
goto end_success;
__get_article_cache_ptr(INEWS_getQID(), aid)->approved = approve;
break;
case '-':
switch (tempstring[2]) {
Expand Down Expand Up @@ -632,6 +635,9 @@ Sint8 INEWS_changeDeletionStatus(Uint32 aid, bool deleteflag) {
}

artinfo = INEWS_digest(aid + 1, 1);

printf("artinfo[0] is %x\n", artinfo);

if (artinfo[0]->deleted == deleteflag) {
INEWS_freeDigest(artinfo);
goto end_success;
Expand All @@ -658,6 +664,7 @@ Sint8 INEWS_changeDeletionStatus(Uint32 aid, bool deleteflag) {
switch(tempstring[0]) {
case '+':
goto end_success;
__get_article_cache_ptr(INEWS_getQID(), aid)->deleted = deleteflag;
break;
case '-':
switch (tempstring[2]) {
Expand Down

0 comments on commit 3efeba4

Please sign in to comment.