diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-01-28 21:30:39 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-01-30 23:35:50 +0000 |
commit | 92ffad1a72bc8c422426d52ac408bd71242dd047 (patch) | |
tree | f592f353068dd2043525dd2cc04d6124a4ed4bc4 /toxav/msi.c | |
parent | 623e9ac331df7323660e21c8a2226523a5ee713b (diff) |
Use nullptr as NULL pointer constant instead of NULL or 0.
This changes only code, no string literals or comments.
Diffstat (limited to 'toxav/msi.c')
-rw-r--r-- | toxav/msi.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/toxav/msi.c b/toxav/msi.c index 882dad04..94b7b537 100644 --- a/toxav/msi.c +++ b/toxav/msi.c | |||
@@ -104,21 +104,21 @@ void msi_register_callback(MSISession *session, msi_action_cb *callback, MSICall | |||
104 | } | 104 | } |
105 | MSISession *msi_new(Messenger *m) | 105 | MSISession *msi_new(Messenger *m) |
106 | { | 106 | { |
107 | if (m == NULL) { | 107 | if (m == nullptr) { |
108 | return NULL; | 108 | return nullptr; |
109 | } | 109 | } |
110 | 110 | ||
111 | MSISession *retu = (MSISession *)calloc(sizeof(MSISession), 1); | 111 | MSISession *retu = (MSISession *)calloc(sizeof(MSISession), 1); |
112 | 112 | ||
113 | if (retu == NULL) { | 113 | if (retu == nullptr) { |
114 | LOGGER_ERROR(m->log, "Allocation failed! Program might misbehave!"); | 114 | LOGGER_ERROR(m->log, "Allocation failed! Program might misbehave!"); |
115 | return NULL; | 115 | return nullptr; |
116 | } | 116 | } |
117 | 117 | ||
118 | if (create_recursive_mutex(retu->mutex) != 0) { | 118 | if (create_recursive_mutex(retu->mutex) != 0) { |
119 | LOGGER_ERROR(m->log, "Failed to init mutex! Program might misbehave"); | 119 | LOGGER_ERROR(m->log, "Failed to init mutex! Program might misbehave"); |
120 | free(retu); | 120 | free(retu); |
121 | return NULL; | 121 | return nullptr; |
122 | } | 122 | } |
123 | 123 | ||
124 | retu->messenger = m; | 124 | retu->messenger = m; |
@@ -133,12 +133,12 @@ MSISession *msi_new(Messenger *m) | |||
133 | } | 133 | } |
134 | int msi_kill(MSISession *session, Logger *log) | 134 | int msi_kill(MSISession *session, Logger *log) |
135 | { | 135 | { |
136 | if (session == NULL) { | 136 | if (session == nullptr) { |
137 | LOGGER_ERROR(log, "Tried to terminate non-existing session"); | 137 | LOGGER_ERROR(log, "Tried to terminate non-existing session"); |
138 | return -1; | 138 | return -1; |
139 | } | 139 | } |
140 | 140 | ||
141 | m_callback_msi_packet((struct Messenger *) session->messenger, NULL, NULL); | 141 | m_callback_msi_packet((struct Messenger *) session->messenger, nullptr, nullptr); |
142 | 142 | ||
143 | if (pthread_mutex_trylock(session->mutex) != 0) { | 143 | if (pthread_mutex_trylock(session->mutex) != 0) { |
144 | LOGGER_ERROR(session->messenger->log, "Failed to acquire lock on msi mutex"); | 144 | LOGGER_ERROR(session->messenger->log, "Failed to acquire lock on msi mutex"); |
@@ -179,7 +179,7 @@ int msi_invite(MSISession *session, MSICall **call, uint32_t friend_number, uint | |||
179 | return -1; | 179 | return -1; |
180 | } | 180 | } |
181 | 181 | ||
182 | if (get_call(session, friend_number) != NULL) { | 182 | if (get_call(session, friend_number) != nullptr) { |
183 | LOGGER_ERROR(session->messenger->log, "Already in a call"); | 183 | LOGGER_ERROR(session->messenger->log, "Already in a call"); |
184 | pthread_mutex_unlock(session->mutex); | 184 | pthread_mutex_unlock(session->mutex); |
185 | return -1; | 185 | return -1; |
@@ -187,7 +187,7 @@ int msi_invite(MSISession *session, MSICall **call, uint32_t friend_number, uint | |||
187 | 187 | ||
188 | (*call) = new_call(session, friend_number); | 188 | (*call) = new_call(session, friend_number); |
189 | 189 | ||
190 | if (*call == NULL) { | 190 | if (*call == nullptr) { |
191 | pthread_mutex_unlock(session->mutex); | 191 | pthread_mutex_unlock(session->mutex); |
192 | return -1; | 192 | return -1; |
193 | } | 193 | } |
@@ -506,8 +506,8 @@ static MSICall *get_call(MSISession *session, uint32_t friend_number) | |||
506 | { | 506 | { |
507 | assert(session); | 507 | assert(session); |
508 | 508 | ||
509 | if (session->calls == NULL || session->calls_tail < friend_number) { | 509 | if (session->calls == nullptr || session->calls_tail < friend_number) { |
510 | return NULL; | 510 | return nullptr; |
511 | } | 511 | } |
512 | 512 | ||
513 | return session->calls[friend_number]; | 513 | return session->calls[friend_number]; |
@@ -518,28 +518,28 @@ MSICall *new_call(MSISession *session, uint32_t friend_number) | |||
518 | 518 | ||
519 | MSICall *rc = (MSICall *)calloc(sizeof(MSICall), 1); | 519 | MSICall *rc = (MSICall *)calloc(sizeof(MSICall), 1); |
520 | 520 | ||
521 | if (rc == NULL) { | 521 | if (rc == nullptr) { |
522 | return NULL; | 522 | return nullptr; |
523 | } | 523 | } |
524 | 524 | ||
525 | rc->session = session; | 525 | rc->session = session; |
526 | rc->friend_number = friend_number; | 526 | rc->friend_number = friend_number; |
527 | 527 | ||
528 | if (session->calls == NULL) { /* Creating */ | 528 | if (session->calls == nullptr) { /* Creating */ |
529 | session->calls = (MSICall **)calloc(sizeof(MSICall *), friend_number + 1); | 529 | session->calls = (MSICall **)calloc(sizeof(MSICall *), friend_number + 1); |
530 | 530 | ||
531 | if (session->calls == NULL) { | 531 | if (session->calls == nullptr) { |
532 | free(rc); | 532 | free(rc); |
533 | return NULL; | 533 | return nullptr; |
534 | } | 534 | } |
535 | 535 | ||
536 | session->calls_tail = session->calls_head = friend_number; | 536 | session->calls_tail = session->calls_head = friend_number; |
537 | } else if (session->calls_tail < friend_number) { /* Appending */ | 537 | } else if (session->calls_tail < friend_number) { /* Appending */ |
538 | MSICall **tmp = (MSICall **)realloc(session->calls, sizeof(MSICall *) * (friend_number + 1)); | 538 | MSICall **tmp = (MSICall **)realloc(session->calls, sizeof(MSICall *) * (friend_number + 1)); |
539 | 539 | ||
540 | if (tmp == NULL) { | 540 | if (tmp == nullptr) { |
541 | free(rc); | 541 | free(rc); |
542 | return NULL; | 542 | return nullptr; |
543 | } | 543 | } |
544 | 544 | ||
545 | session->calls = tmp; | 545 | session->calls = tmp; |
@@ -548,7 +548,7 @@ MSICall *new_call(MSISession *session, uint32_t friend_number) | |||
548 | uint32_t i = session->calls_tail + 1; | 548 | uint32_t i = session->calls_tail + 1; |
549 | 549 | ||
550 | for (; i < friend_number; i ++) { | 550 | for (; i < friend_number; i ++) { |
551 | session->calls[i] = NULL; | 551 | session->calls[i] = nullptr; |
552 | } | 552 | } |
553 | 553 | ||
554 | rc->prev = session->calls[session->calls_tail]; | 554 | rc->prev = session->calls[session->calls_tail]; |
@@ -567,7 +567,7 @@ MSICall *new_call(MSISession *session, uint32_t friend_number) | |||
567 | void kill_call(MSICall *call) | 567 | void kill_call(MSICall *call) |
568 | { | 568 | { |
569 | /* Assume that session mutex is locked */ | 569 | /* Assume that session mutex is locked */ |
570 | if (call == NULL) { | 570 | if (call == nullptr) { |
571 | return; | 571 | return; |
572 | } | 572 | } |
573 | 573 | ||
@@ -594,7 +594,7 @@ void kill_call(MSICall *call) | |||
594 | goto CLEAR_CONTAINER; | 594 | goto CLEAR_CONTAINER; |
595 | } | 595 | } |
596 | 596 | ||
597 | session->calls[call->friend_number] = NULL; | 597 | session->calls[call->friend_number] = nullptr; |
598 | free(call); | 598 | free(call); |
599 | return; | 599 | return; |
600 | 600 | ||
@@ -602,7 +602,7 @@ CLEAR_CONTAINER: | |||
602 | session->calls_head = session->calls_tail = 0; | 602 | session->calls_head = session->calls_tail = 0; |
603 | free(session->calls); | 603 | free(session->calls); |
604 | free(call); | 604 | free(call); |
605 | session->calls = NULL; | 605 | session->calls = nullptr; |
606 | } | 606 | } |
607 | void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t status, void *data) | 607 | void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t status, void *data) |
608 | { | 608 | { |
@@ -616,7 +616,7 @@ void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t status, void * | |||
616 | pthread_mutex_lock(session->mutex); | 616 | pthread_mutex_lock(session->mutex); |
617 | MSICall *call = get_call(session, friend_number); | 617 | MSICall *call = get_call(session, friend_number); |
618 | 618 | ||
619 | if (call == NULL) { | 619 | if (call == nullptr) { |
620 | pthread_mutex_unlock(session->mutex); | 620 | pthread_mutex_unlock(session->mutex); |
621 | return; | 621 | return; |
622 | } | 622 | } |
@@ -810,7 +810,7 @@ void handle_msi_packet(Messenger *m, uint32_t friend_number, const uint8_t *data | |||
810 | pthread_mutex_lock(session->mutex); | 810 | pthread_mutex_lock(session->mutex); |
811 | MSICall *call = get_call(session, friend_number); | 811 | MSICall *call = get_call(session, friend_number); |
812 | 812 | ||
813 | if (call == NULL) { | 813 | if (call == nullptr) { |
814 | if (msg.request.value != requ_init) { | 814 | if (msg.request.value != requ_init) { |
815 | send_error(m, friend_number, msi_EStrayMessage); | 815 | send_error(m, friend_number, msi_EStrayMessage); |
816 | pthread_mutex_unlock(session->mutex); | 816 | pthread_mutex_unlock(session->mutex); |
@@ -819,7 +819,7 @@ void handle_msi_packet(Messenger *m, uint32_t friend_number, const uint8_t *data | |||
819 | 819 | ||
820 | call = new_call(session, friend_number); | 820 | call = new_call(session, friend_number); |
821 | 821 | ||
822 | if (call == NULL) { | 822 | if (call == nullptr) { |
823 | send_error(m, friend_number, msi_ESystem); | 823 | send_error(m, friend_number, msi_ESystem); |
824 | pthread_mutex_unlock(session->mutex); | 824 | pthread_mutex_unlock(session->mutex); |
825 | return; | 825 | return; |