summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.me.uk>2011-10-17 18:39:13 +0100
committerNick White <git@njw.me.uk>2011-10-17 18:39:13 +0100
commit82908257a64d4fd67785c76ab33b0392bc9d9724 (patch)
treedca2c21f350ed63a55fbfec9add2f0b1e504f83f
parentc3bcc40c5f7ad3e39a35a8f358e7ba408662d873 (diff)
Take care to initialise variables before use
-rw-r--r--getabook.c10
-rw-r--r--getgbook.c6
-rw-r--r--plans/bnbook2
3 files changed, 13 insertions, 5 deletions
diff --git a/getabook.c b/getabook.c
index 9f4015b..f575469 100644
--- a/getabook.c
+++ b/getabook.c
@@ -61,7 +61,7 @@ int fillurls(char *buf) {
int getpagelist()
{
- char url[URLMAX], b[STRMAX];
+ char url[URLMAX], b[STRMAX] = "";
char *buf = NULL;
char *s, *c;
int i;
@@ -79,8 +79,10 @@ int getpagelist()
bookid[10] = '\0';
}
- if((s = strstr(buf, "\"litbPages\":[")) == NULL)
+ if((s = strstr(buf, "\"litbPages\":[")) == NULL) {
+ free(buf);
return 1;
+ }
s+=strlen("\"litbPages\":[");
for(i=0, p=pages[0];*s && i<MAXPAGES; s++) {
@@ -143,6 +145,7 @@ int main(int argc, char *argv[])
char in[16];
int a, i, n;
FILE *f;
+ DIR *d;
if(argc < 2 || argc > 3 ||
(argc == 3 && (argv[1][0]!='-' || argv[1][1] != 'n'))
@@ -160,10 +163,11 @@ int main(int argc, char *argv[])
return 1;
}
- if(!(opendir(bookdir) || !mkdir(bookdir, S_IRWXU))) {
+ if(!((d = opendir(bookdir)) || !mkdir(bookdir, S_IRWXU))) {
fprintf(stderr, "Could not create directory %s\n", bookdir);
return 1;
}
+ if(d) closedir(d);
if(argc == 2) {
for(i=0; i<numpages; i++) {
diff --git a/getgbook.c b/getgbook.c
index a06573e..846dfe7 100644
--- a/getgbook.c
+++ b/getgbook.c
@@ -71,7 +71,7 @@ int getpagelist()
int getpageurls(char *pagecode, char *cookie) {
char url[URLMAX], code[STRMAX], m[STRMAX];
- char *c, *d, *p, *q, *buf = NULL;
+ char *c = NULL, *d, *p, *q, *buf = NULL;
int i, j;
snprintf(url, URLMAX, "/books?id=%s&pg=%s&jscmd=click3&q=subject:a", bookid, pagecode);
@@ -162,6 +162,7 @@ int main(int argc, char *argv[])
char in[16];
int a, i, n;
FILE *f;
+ DIR *d;
if(argc < 2 || argc > 3 || (argc == 3 && (argv[1][0]!='-'
|| (argv[1][1] != 'c' && argv[1][1] != 'n')))
@@ -185,10 +186,11 @@ int main(int argc, char *argv[])
return 1;
}
- if(!(opendir(bookdir) || !mkdir(bookdir, S_IRWXU))) {
+ if(!((d = opendir(bookdir)) || !mkdir(bookdir, S_IRWXU))) {
fprintf(stderr, "Could not create directory %s\n", bookdir);
return 1;
}
+ if(d) closedir(d);
if(argc == 2) {
for(i=0; i<totalpages; i++) {
diff --git a/plans/bnbook b/plans/bnbook
index ea7200f..f5dd33e 100644
--- a/plans/bnbook
+++ b/plans/bnbook
@@ -23,3 +23,5 @@ http://search2.barnesandnoble.com/digbooks/proxy/54/9780312361983/%d/fp
the %d can be replaced with the page number
requesting a page which isn't available
(freevendstatus="false") returns the standard book swf
+
+note that cookies have to be sent for the fp stuff to work. cookies from the homepage work fine