summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-10-17 22:07:54 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-10-17 22:07:54 +0000
commit2f0f69d325341dfc8e7595adb86944b09c1b0710 (patch)
tree1f7cf7dbe06fe4ec858d6cf3e837e139bde2756a
parent82c3e5f920f132ff266fa09f4b22d72c595eba3c (diff)
etrophy: add checks for null on api funcs
SVN revision: 78141
-rw-r--r--src/lib/etrophy.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/src/lib/etrophy.c b/src/lib/etrophy.c
index c6b729e..ff65f8f 100644
--- a/src/lib/etrophy.c
+++ b/src/lib/etrophy.c
@@ -128,8 +128,11 @@ _trophy_shutdown(void)
128EAPI Etrophy_Trophy * 128EAPI Etrophy_Trophy *
129etrophy_trophy_new(const char *name, const char *description, Etrophy_Trophy_Visibility visibility, unsigned int goal) 129etrophy_trophy_new(const char *name, const char *description, Etrophy_Trophy_Visibility visibility, unsigned int goal)
130{ 130{
131 Etrophy_Trophy *trophy = calloc(1, sizeof(Etrophy_Trophy)); 131 Etrophy_Trophy *trophy;
132
133 EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
132 134
135 trophy = calloc(1, sizeof(Etrophy_Trophy));
133 if (!trophy) 136 if (!trophy)
134 { 137 {
135 ERR("Could not calloc Etrophy_Trophy."); 138 ERR("Could not calloc Etrophy_Trophy.");
@@ -148,6 +151,7 @@ etrophy_trophy_new(const char *name, const char *description, Etrophy_Trophy_Vis
148EAPI void 151EAPI void
149etrophy_trophy_free(Etrophy_Trophy *trophy) 152etrophy_trophy_free(Etrophy_Trophy *trophy)
150{ 153{
154 EINA_SAFETY_ON_NULL_RETURN(trophy);
151 eina_stringshare_del(trophy->name); 155 eina_stringshare_del(trophy->name);
152 eina_stringshare_del(trophy->description); 156 eina_stringshare_del(trophy->description);
153 free(trophy); 157 free(trophy);
@@ -156,18 +160,21 @@ etrophy_trophy_free(Etrophy_Trophy *trophy)
156EAPI inline const char * 160EAPI inline const char *
157etrophy_trophy_name_get(const Etrophy_Trophy *trophy) 161etrophy_trophy_name_get(const Etrophy_Trophy *trophy)
158{ 162{
163 EINA_SAFETY_ON_NULL_RETURN_VAL(trophy, NULL);
159 return trophy->name; 164 return trophy->name;
160} 165}
161 166
162EAPI inline const char * 167EAPI inline const char *
163etrophy_trophy_description_get(const Etrophy_Trophy *trophy) 168etrophy_trophy_description_get(const Etrophy_Trophy *trophy)
164{ 169{
170 EINA_SAFETY_ON_NULL_RETURN_VAL(trophy, NULL);
165 return trophy->description; 171 return trophy->description;
166} 172}
167 173
168EAPI inline Etrophy_Trophy_Visibility 174EAPI inline Etrophy_Trophy_Visibility
169etrophy_trophy_visibility_get(const Etrophy_Trophy *trophy) 175etrophy_trophy_visibility_get(const Etrophy_Trophy *trophy)
170{ 176{
177 EINA_SAFETY_ON_NULL_RETURN_VAL(trophy, 0);
171 return trophy->visibility; 178 return trophy->visibility;
172} 179}
173 180
@@ -175,6 +182,7 @@ EAPI inline void
175etrophy_trophy_goal_get(const Etrophy_Trophy *trophy, unsigned int *goal, 182etrophy_trophy_goal_get(const Etrophy_Trophy *trophy, unsigned int *goal,
176 unsigned int *counter) 183 unsigned int *counter)
177{ 184{
185 EINA_SAFETY_ON_NULL_RETURN(trophy);
178 if (goal) *goal = trophy->goal; 186 if (goal) *goal = trophy->goal;
179 if (counter) *counter = trophy->counter; 187 if (counter) *counter = trophy->counter;
180} 188}
@@ -182,6 +190,8 @@ etrophy_trophy_goal_get(const Etrophy_Trophy *trophy, unsigned int *goal,
182EAPI inline void 190EAPI inline void
183etrophy_trophy_counter_increment(Etrophy_Trophy *trophy, unsigned int value) 191etrophy_trophy_counter_increment(Etrophy_Trophy *trophy, unsigned int value)
184{ 192{
193 EINA_SAFETY_ON_NULL_RETURN(trophy);
194
185 if (trophy->counter == trophy->goal) return; 195 if (trophy->counter == trophy->goal) return;
186 196
187 trophy->counter += value; 197 trophy->counter += value;
@@ -194,12 +204,14 @@ etrophy_trophy_counter_increment(Etrophy_Trophy *trophy, unsigned int value)
194EAPI inline Eina_Bool 204EAPI inline Eina_Bool
195etrophy_trophy_earned_get(const Etrophy_Trophy *trophy) 205etrophy_trophy_earned_get(const Etrophy_Trophy *trophy)
196{ 206{
207 EINA_SAFETY_ON_NULL_RETURN_VAL(trophy, EINA_FALSE);
197 return (trophy->goal == trophy->counter); 208 return (trophy->goal == trophy->counter);
198} 209}
199 210
200EAPI inline unsigned int 211EAPI inline unsigned int
201etrophy_trophy_date_get(const Etrophy_Trophy *trophy) 212etrophy_trophy_date_get(const Etrophy_Trophy *trophy)
202{ 213{
214 EINA_SAFETY_ON_NULL_RETURN_VAL(trophy, 0);
203 return trophy->date; 215 return trophy->date;
204} 216}
205 217
@@ -232,8 +244,11 @@ _lock_shutdown(void)
232EAPI Etrophy_Lock * 244EAPI Etrophy_Lock *
233etrophy_lock_new(const char *name, Etrophy_Lock_State state) 245etrophy_lock_new(const char *name, Etrophy_Lock_State state)
234{ 246{
235 Etrophy_Lock *lock = calloc(1, sizeof(Etrophy_Lock)); 247 Etrophy_Lock *lock;
248
249 EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
236 250
251 lock = calloc(1, sizeof(Etrophy_Lock));
237 if (!lock) 252 if (!lock)
238 { 253 {
239 ERR("Could not calloc Etrophy_Lock."); 254 ERR("Could not calloc Etrophy_Lock.");
@@ -250,6 +265,7 @@ etrophy_lock_new(const char *name, Etrophy_Lock_State state)
250EAPI void 265EAPI void
251etrophy_lock_free(Etrophy_Lock *lock) 266etrophy_lock_free(Etrophy_Lock *lock)
252{ 267{
268 EINA_SAFETY_ON_NULL_RETURN(lock);
253 eina_stringshare_del(lock->name); 269 eina_stringshare_del(lock->name);
254 free(lock); 270 free(lock);
255} 271}
@@ -257,12 +273,14 @@ etrophy_lock_free(Etrophy_Lock *lock)
257EAPI inline const char * 273EAPI inline const char *
258etrophy_lock_name_get(const Etrophy_Lock *lock) 274etrophy_lock_name_get(const Etrophy_Lock *lock)
259{ 275{
276 EINA_SAFETY_ON_NULL_RETURN_VAL(lock, NULL);
260 return lock->name; 277 return lock->name;
261} 278}
262 279
263EAPI inline Etrophy_Lock_State 280EAPI inline Etrophy_Lock_State
264etrophy_lock_state_get(const Etrophy_Lock *lock) 281etrophy_lock_state_get(const Etrophy_Lock *lock)
265{ 282{
283 EINA_SAFETY_ON_NULL_RETURN_VAL(lock, 0);
266 return lock->state; 284 return lock->state;
267} 285}
268 286
@@ -278,6 +296,7 @@ etrophy_lock_state_set(Etrophy_Lock *lock, Etrophy_Lock_State state)
278EAPI inline unsigned int 296EAPI inline unsigned int
279etrophy_lock_date_get(const Etrophy_Lock *lock) 297etrophy_lock_date_get(const Etrophy_Lock *lock)
280{ 298{
299 EINA_SAFETY_ON_NULL_RETURN_VAL(lock, 0);
281 return lock->date; 300 return lock->date;
282} 301}
283 302
@@ -330,6 +349,7 @@ etrophy_score_new(const char *player_name, int score)
330EAPI void 349EAPI void
331etrophy_score_free(Etrophy_Score *escore) 350etrophy_score_free(Etrophy_Score *escore)
332{ 351{
352 EINA_SAFETY_ON_NULL_RETURN(escore);
333 eina_stringshare_del(escore->player_name); 353 eina_stringshare_del(escore->player_name);
334 free(escore); 354 free(escore);
335} 355}
@@ -337,18 +357,21 @@ etrophy_score_free(Etrophy_Score *escore)
337EAPI inline const char * 357EAPI inline const char *
338etrophy_score_player_name_get(const Etrophy_Score *escore) 358etrophy_score_player_name_get(const Etrophy_Score *escore)
339{ 359{
360 EINA_SAFETY_ON_NULL_RETURN_VAL(escore, NULL);
340 return escore->player_name; 361 return escore->player_name;
341} 362}
342 363
343EAPI inline int 364EAPI inline int
344etrophy_score_score_get(const Etrophy_Score *escore) 365etrophy_score_score_get(const Etrophy_Score *escore)
345{ 366{
367 EINA_SAFETY_ON_NULL_RETURN_VAL(escore, 0);
346 return escore->score; 368 return escore->score;
347} 369}
348 370
349EAPI inline unsigned int 371EAPI inline unsigned int
350etrophy_score_date_get(const Etrophy_Score *escore) 372etrophy_score_date_get(const Etrophy_Score *escore)
351{ 373{
374 EINA_SAFETY_ON_NULL_RETURN_VAL(escore, 0);
352 return escore->date; 375 return escore->date;
353} 376}
354 377
@@ -379,8 +402,11 @@ _level_shutdown(void)
379EAPI Etrophy_Level * 402EAPI Etrophy_Level *
380etrophy_level_new(const char *name) 403etrophy_level_new(const char *name)
381{ 404{
382 Etrophy_Level *level = calloc(1, sizeof(Etrophy_Level)); 405 Etrophy_Level *level;
406
407 EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
383 408
409 level = calloc(1, sizeof(Etrophy_Level));
384 if (!level) 410 if (!level)
385 { 411 {
386 ERR("Could not calloc Etrophy_Level."); 412 ERR("Could not calloc Etrophy_Level.");
@@ -396,6 +422,7 @@ etrophy_level_new(const char *name)
396EAPI void 422EAPI void
397etrophy_level_free(Etrophy_Level *level) 423etrophy_level_free(Etrophy_Level *level)
398{ 424{
425 EINA_SAFETY_ON_NULL_RETURN(level);
399 eina_stringshare_del(level->name); 426 eina_stringshare_del(level->name);
400 if (level->scores) 427 if (level->scores)
401 { 428 {
@@ -409,6 +436,7 @@ etrophy_level_free(Etrophy_Level *level)
409EAPI inline const char * 436EAPI inline const char *
410etrophy_level_name_get(const Etrophy_Level *level) 437etrophy_level_name_get(const Etrophy_Level *level)
411{ 438{
439 EINA_SAFETY_ON_NULL_RETURN_VAL(level, NULL);
412 return level->name; 440 return level->name;
413} 441}
414 442
@@ -525,6 +553,7 @@ etrophy_gamescore_new(const char *gamename)
525EAPI void 553EAPI void
526etrophy_gamescore_free(Etrophy_Gamescore *gamescore) 554etrophy_gamescore_free(Etrophy_Gamescore *gamescore)
527{ 555{
556 EINA_SAFETY_ON_NULL_RETURN(gamescore);
528 if (gamescore->levels) 557 if (gamescore->levels)
529 { 558 {
530 Etrophy_Level *levels_elem; 559 Etrophy_Level *levels_elem;