Skip to content

Commit b7f6e0e

Browse files
committedApr 22, 2017
Emerg patch .2
fix bugs in mkret, getret than cause segfault.
1 parent f1ab88b commit b7f6e0e

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed
 

‎Makefile

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ win:libsbl.dll
3838
libsbl.so:$(FILES)
3939
$(CC) $(CFLAGS-UNIX) $(FILES) -o libsbl.so
4040

41-
libsbl.dll:$(OBJ-WIN)
41+
libsbl.dll:$(FILES)
4242
$(CC) $(CFLAGS-WIN) $(FILES) -o libsbl.dll
4343

44-
44+
install:
45+
if [ -f libsbl.so ] ; then cp libsbl.so /usr/lib; elif [ -f libsbl.dll ] ; then cp libsbl.dll /usr/lib; fi
46+
4547
.PHONY:clean err
4648
clean:
4749
$(RM) *.o *.a -r

‎include/slib.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929

3030
#ifndef SBLLIB_VERSION
31-
#define SBLLIB_VERSION 2.3.1
31+
#define SBLLIB_VERSION 2.3.2
3232

3333
#include <string.h>
3434
#include <stdio.h>
@@ -155,8 +155,8 @@ typedef struct Stack
155155

156156
typedef struct mtrt
157157
{
158-
void **val;
159158
size_t lenth;
159+
int **val;
160160
}mtret;
161161

162162

@@ -281,10 +281,10 @@ OPT char* ultoaS(unsigned long value, char* string, int radix);
281281
D_TESTING OPT int colorprintf(enum cpfcolors fcolor,ccp format,...);
282282

283283

284-
OPT void *getret(mtret *ret);
284+
OPT int *getret(mtret ret);
285285

286286

287-
OPT mtret *mkret(size_t lenth,...);
287+
OPT mtret mkret(size_t lenth,...);
288288

289289
#if ! PLAT
290290
OPT int getch(void);

‎main/mret.c

+11-9
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,34 @@
2525
#include "slib.h"
2626
int retind=0;
2727

28-
mtret *mkret(size_t lenth,...)
28+
mtret mkret(size_t lenth,...)
2929
{
30-
mtret *ret;
31-
void **elems=malloc(sizeof(int*)*lenth);
30+
mtret ret,mnull={0,NULL};
31+
int **elems=malloc(sizeof(int*)*lenth);
3232
int count=0;
3333
va_list args;
3434
if(elems==NULL)
3535
{
3636
serr=1;
37-
return NULL;
37+
return mnull;
3838
}
3939
va_start(args,lenth);
4040

41-
ret->lenth=lenth;
41+
ret.lenth=lenth;
4242
for(;count<lenth;++count)
4343
{
4444
elems[count]=va_arg(args,int*);
4545
}
46-
ret->val=elems;
46+
//memmove(elems,ret.val,sizeof(int*)*lenth);
47+
ret.val=elems;
4748
va_end(args);
48-
free(elems);
49+
//free(elems);
50+
elems=NULL;
4951
return ret;
5052
}
5153

5254

53-
void *getret(mtret *ret)
55+
int *getret(mtret ret)
5456
{
55-
return retind<ret->lenth?ret->val[retind++]:NULL;
57+
return ((retind<ret.lenth)?(ret.val[retind++]):(free(ret.val),NULL));
5658
}

1 commit comments

Comments
 (1)

myzhang1029 commented on Apr 22, 2017

@myzhang1029
OwnerAuthor

Make install is also supported

Please sign in to comment.