summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2013-08-15 15:34:27 +0200
committerFlorian Hahn <flo@fhahn.com>2013-08-15 15:34:27 +0200
commit3590f0a521812cc2d76e344c53640f8b823ac4d0 (patch)
tree30f88b2f6b1a495bda14018ea461a42b2a83b6bc /core
parent70b633d81634fb7369065cb902deee87ac84b7ca (diff)
Check return value of realloc_friendlist and return FAERR_NOMEM on error
Diffstat (limited to 'core')
-rw-r--r--core/Messenger.c11
-rw-r--r--core/Messenger.h1
2 files changed, 9 insertions, 3 deletions
diff --git a/core/Messenger.c b/core/Messenger.c
index 690a81b1..bed59d4d 100644
--- a/core/Messenger.c
+++ b/core/Messenger.c
@@ -120,6 +120,7 @@ void getaddress(Messenger *m, uint8_t *address)
120 * return FAERR_BADCHECKSUM if bad checksum in address 120 * return FAERR_BADCHECKSUM if bad checksum in address
121 * return FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different 121 * return FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different
122 * (the nospam for that friend was set to the new one) 122 * (the nospam for that friend was set to the new one)
123 * return FAERR_NOMEM if increasing the friend list size fails
123 */ 124 */
124int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length) 125int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length)
125{ 126{
@@ -148,7 +149,8 @@ int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length)
148 } 149 }
149 150
150 /* resize the friend list if necessary */ 151 /* resize the friend list if necessary */
151 realloc_friendlist(m, m->numfriends + 1); 152 if (realloc_friendlist(m, m->numfriends + 1) != 0)
153 return FAERR_NOMEM;
152 154
153 uint32_t i; 155 uint32_t i;
154 for (i = 0; i <= m->numfriends; ++i) { 156 for (i = 0; i <= m->numfriends; ++i) {
@@ -180,7 +182,8 @@ int m_addfriend_norequest(Messenger *m, uint8_t * client_id)
180 return -1; 182 return -1;
181 183
182 /* resize the friend list if necessary */ 184 /* resize the friend list if necessary */
183 realloc_friendlist(m, m->numfriends + 1); 185 if (realloc_friendlist(m, m->numfriends + 1) != 0)
186 return FAERR_NOMEM;
184 187
185 uint32_t i; 188 uint32_t i;
186 for (i = 0; i <= m->numfriends; ++i) { 189 for (i = 0; i <= m->numfriends; ++i) {
@@ -221,7 +224,9 @@ int m_delfriend(Messenger *m, int friendnumber)
221 break; 224 break;
222 } 225 }
223 m->numfriends = i; 226 m->numfriends = i;
224 realloc_friendlist(m, m->numfriends + 1); 227
228 if (realloc_friendlist(m, m->numfriends + 1) != 0)
229 return FAERR_NOMEM;
225 230
226 return 0; 231 return 0;
227} 232}
diff --git a/core/Messenger.h b/core/Messenger.h
index a2add19d..a7e0aab5 100644
--- a/core/Messenger.h
+++ b/core/Messenger.h
@@ -63,6 +63,7 @@ extern "C" {
63#define FAERR_UNKNOWN -5 63#define FAERR_UNKNOWN -5
64#define FAERR_BADCHECKSUM -6 64#define FAERR_BADCHECKSUM -6
65#define FAERR_SETNEWNOSPAM -7 65#define FAERR_SETNEWNOSPAM -7
66#define FAERR_NOMEM -8
66 67
67/* don't assume MAX_STATUSMESSAGE_LENGTH will stay at 128, it may be increased 68/* don't assume MAX_STATUSMESSAGE_LENGTH will stay at 128, it may be increased
68 to an absurdly large number later */ 69 to an absurdly large number later */