aboutsummaryrefslogtreecommitdiff
path: root/contactList.c
diff options
context:
space:
mode:
authorache <ache@ache.one>2018-11-08 16:40:47 +0100
committerache <ache@ache.one>2018-11-08 16:40:47 +0100
commit6cb43717cbbe8380d2aeb382d2b6f350bab74494 (patch)
tree717ee722cd50ebcbd4979b4e7156c1b860cebf88 /contactList.c
parentFix message showing bug (diff)
Improve loggers
Diffstat (limited to 'contactList.c')
-rw-r--r--contactList.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/contactList.c b/contactList.c
index b6d9385..642aa19 100644
--- a/contactList.c
+++ b/contactList.c
@@ -71,24 +71,30 @@ int fillContactList(char* filename) {
free(contactList);
}
- if( !file )
+ if( !file ) {
+ perror("Unable to read contact file");
return 1;
+ }
int c = 0;
int v = 0;
while( (c = fgetc(file)) != EOF ) {
if( c == ';' ) {
v++;
- if( v == 3)
+ if( v >= 3) {
+ fprintf(stderr, "Invalid format (contact file) : too many field");
return 2; // Invalid
+ }
}
if( c == '\n' ) {
if( v == 2 ) {
v = 0;
nbContacts++;
}
- else // Pas assez
+ else {// Pas assez
+ fprintf(stderr, "Invalid format (contact file) : not enougth field");
return 2; // Invalid format
+ }
}
}
if( v == 1 )
@@ -115,6 +121,7 @@ int fillContactList(char* filename) {
display_nameLength = 0;
break;
default:
+ fprintf(stderr, "Invalid format (contact file)");
return 2; // Invalid
}
} else if( c == '\n' ) {
@@ -126,23 +133,28 @@ int fillContactList(char* filename) {
contactList[i].hasNewMessage = 0;
contactList[i].conversation = NULL;
}
- else
+ else {
+ fprintf(stderr, "Invalid format (contact file)");
return 2; // Invalid format
+ }
} else {
if( v == 0) {
contactList[i].name[nameLength++] = c;
if( nameLength > (sizeof contactList[i].name -1) ) {
+ fprintf(stderr, "too long name ?");
return 3;
}
}else if( v == 1) {
contactList[i].display_name[display_nameLength++] = c;
if( display_nameLength > (sizeof contactList[i].display_name -1) ) {
+ fprintf(stderr, "too display name ?");
return 9;
}
} else {
contactList[i].number[numberLength++] = c;
if( numberLength > (sizeof contactList[i].number -1) ) {
puts(contactList[i].number);
+ fprintf(stderr, "too long number ?");
return 27+i;
}
}