shithub: mpl

Download patch

ref: 80d1babd847f1e946ac37b7e74389049b99cc371
parent: 5d597414f63bb9c98aa442d3fd6d33fc230848b4
author: Jacob Moody <jsmoody@iastate.edu>
date: Thu Dec 5 12:29:58 EST 2019

Fix wrong write of nul value
setmalloctag for unmarshal functions

--- a/fncs.h
+++ b/fncs.h
@@ -26,8 +26,9 @@
 Point	drawalbum(Album*, Image*, Image*, Point, int, Channel*);
 Image*	convpic(int, char*);
 Image*	convpicbuf(uchar*, uvlong, char*);
-void	drawlibrary(Album*, Album*, Album*, Image*, Image*, int, Channel*);
+void	drawlibrary(Lib*, Point, Image*, Image*, Channel*);
 void	drawvolume(int, Image*);
+void	drawlists(Point,Image*,Image*,Image*,Channel*);
 
 /* dir.c */
 int		file2song(Song*, char*,int);
@@ -41,6 +42,9 @@
 void	mapinsert(Hmap*,char*,void*);
 int		mapdel(Hmap*,char*);
 void*	mapget(Hmap*,char*);
+void	freemap(Hmap*);
+int		mapdump(Hmap*,void**,int);
+int		mapdumpkey(Hmap*,char**,int);
 
 /* lib.c */
 void	spawnlib(Channel*,Channel*,Channel*,Channel*,Channel*,char*);
@@ -53,9 +57,9 @@
 
 /* index.c */
 void	marshalstr(int,char*);
-void	unmarshalstr(int,char**);
+char*	unmarshalstr(int);
 void	marshalrune(int,Rune*);
-void	unmarshalrun(int,Rune**);
+Rune*	unmarshalrune(int);
 void	marshalalbum(int,Album*);
 void	unmarshalalbum(int,Album*);
 void	marshallib(int,Lib*);
@@ -62,5 +66,6 @@
 void	unmarshallib(int,Lib*);
 
 /* list.c */
+void	libdir(char*,int);
 void	dumplib(Lib*);
 void	loadlib(Lib*);
--- a/index.c
+++ b/index.c
@@ -27,17 +27,20 @@
 	}
 }
 
-void
-unmarshalrune(int fd, Rune **r)
+Rune*
+unmarshalrune(int fd)
 {
-	static uchar buf[128];
+	static char buf[128];
+	Rune *r;
 	uchar n;
 	read(fd, &n, sizeof n);
 	if(n == 0)
-		return;
+		return nil;
 	read(fd, buf, n);
 	buf[n] = '\0';
-	*r = runesmprint("%s", (char*)buf);
+	r = runesmprint("%s", buf);
+	setmalloctag(r, getcallerpc(&fd));
+	return r;
 }
 
 void
@@ -48,14 +51,17 @@
 	write(fd, s, n);
 }
 
-void
-unmarshalstr(int fd, char **s)
+char*
+unmarshalstr(int fd)
 {
 	uint n;
+	char *s;
 	read(fd, &n, sizeof n);
-	*s = emalloc(n+1);
+	s = emalloc(n+1);
+	setmalloctag(s, getcallerpc(&fd));
 	s[n] = '\0';
-	read(fd, *s, n);
+	read(fd, s, n);
+	return s;
 }
 
 void
@@ -73,9 +79,10 @@
 unmarshalvorbis(int fd, VorbisMeta **v)
 {
 	*v = emalloc(sizeof(VorbisMeta));
-	unmarshalrune(fd, &((*v)->title));
-	unmarshalrune(fd, &((*v)->artist));
-	unmarshalrune(fd, &((*v)->album));
+	setmalloctag(*v, getcallerpc(&fd));
+	(*v)->title = unmarshalrune(fd);
+	(*v)->artist = unmarshalrune(fd);
+	(*v)->album = unmarshalrune(fd);
 	read(fd, &((*v)->year), sizeof (*v)->year);
 	read(fd, &((*v)->tracknumber), sizeof (*v)->tracknumber);
 }
@@ -93,7 +100,7 @@
 unmarshalflacpic(int fd, FlacPic **p)
 {
 	*p = emalloc(sizeof(FlacPic));
-	unmarshalstr(fd, &((*p)->mime));
+	(*p)->mime = unmarshalstr(fd);
 	read(fd, &((*p)->size), sizeof (*p)->size);
 	read(fd, (*p)->data, (*p)->size);
 }
@@ -128,11 +135,11 @@
 unmarshalid3(int fd, ID3v1 **id)
 {
 	*id = emalloc(sizeof(ID3v1));
-	unmarshalrune(fd, &((*id)->title));
-	unmarshalrune(fd, &((*id)->artist));
-	unmarshalrune(fd, &((*id)->album));
+	(*id)->title = unmarshalrune(fd);
+	(*id)->artist = unmarshalrune(fd);
+	(*id)->album = unmarshalrune(fd);
 	read(fd, &((*id)->year), sizeof (*id)->year);
-	unmarshalrune(fd, &((*id)->comment));
+	(*id)->comment	= unmarshalrune(fd);
 	read(fd, &((*id)->genre), sizeof (*id)->genre);
 }
 
@@ -167,7 +174,7 @@
 	default:
 		sysfatal("not recognized or unsupported format");
 	}
-	unmarshalstr(fd, &(s->path));
+	s->path = unmarshalstr(fd);
 }
 
 void
@@ -188,12 +195,13 @@
 unmarshalalbum(int fd, Album *a)
 {
 	int i, havepic;
-	unmarshalrune(fd, &(a->name));
+	a->name = unmarshalrune(fd);
 	read(fd, &(a->nsong), sizeof a->nsong);
 	read(fd, &havepic, sizeof havepic);
 	if(havepic)
 		a->cover = readimage(display, fd, 0);
 	a->songs = emalloc(sizeof(Song)*a->nsong);
+	setmalloctag(a->songs, getcallerpc(&fd));
 	for(i=0;i<a->nsong;i++)
 		unmarshalsong(fd, a->songs+i);
 }
@@ -214,6 +222,7 @@
 	l->cursong = 0;
 	read(fd, &(l->nalbum), sizeof l->nalbum);
 	l->start = emalloc(sizeof(Album)*l->nalbum);
+	setmalloctag(l->start, getcallerpc(&fd));
 	for(i=0;i<l->nalbum;i++)
 		unmarshalalbum(fd, l->start+i);
 	l->stop = l->start+i;