From 6cb43717cbbe8380d2aeb382d2b6f350bab74494 Mon Sep 17 00:00:00 2001 From: ache Date: Thu, 8 Nov 2018 16:40:47 +0100 Subject: Improve loggers --- contactList.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'contactList.c') 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; } } -- cgit v1.2.3