Stefan Schuermans commited on 2017-02-11 09:44:10
Showing 6 changed files, with 25 additions and 20 deletions.
| ... | ... |
@@ -62,11 +62,13 @@ bool cbEntity(const class dimeState * const state, class dimeEntity *entity, |
| 62 | 62 |
pLayer = &gLayerNetwork; |
| 63 | 63 |
else if (strLayerName.substr(0, 6) == "cable ") {
|
| 64 | 64 |
unsigned int no = 0; |
| 65 |
- sscanf(strLayerName.substr(6).c_str(), "%x", &no); |
|
| 65 |
+ if (sscanf(strLayerName.substr(6).c_str(), "%x", &no) != 1) |
|
| 66 |
+ no = 0; // cable 0 by default |
|
| 66 | 67 |
pLayer = &gLayerCables[no]; |
| 67 | 68 |
} else if (strLayerName.substr(0, 12) == "distributor ") {
|
| 68 | 69 |
unsigned int no = 0; |
| 69 |
- sscanf(strLayerName.substr(12).c_str(), "%x", &no); |
|
| 70 |
+ if (sscanf(strLayerName.substr(12).c_str(), "%x", &no) != 1) |
|
| 71 |
+ no = 0; // distributor 0 by default |
|
| 70 | 72 |
pLayer = &gLayerDistributors[no]; |
| 71 | 73 |
} |
| 72 | 74 |
else |
| ... | ... |
@@ -23,7 +23,7 @@ |
| 23 | 23 |
#include <string.h> |
| 24 | 24 |
|
| 25 | 25 |
#ifdef WINDOWS |
| 26 |
-extern inline char * strerror_r(int errnum, char *buf, size_t buflen) |
|
| 26 |
+static inline char * strerror_r(int errnum, char *buf, size_t buflen) |
|
| 27 | 27 |
{
|
| 28 | 28 |
strncpy(buf, strerror(errnum), buflen); |
| 29 | 29 |
if (buflen >= 1) |
| ... | ... |
@@ -52,7 +52,7 @@ typedef uint16_t in_port_t; |
| 52 | 52 |
|
| 53 | 53 |
#ifndef WINDOWS |
| 54 | 54 |
/** closesocket() only exists for Windows,other OSes just use close() */ |
| 55 |
-extern inline int closesocket(int fd) |
|
| 55 |
+static inline int closesocket(int fd) |
|
| 56 | 56 |
{
|
| 57 | 57 |
return close(fd); |
| 58 | 58 |
} |
| ... | ... |
@@ -63,7 +63,7 @@ extern inline int closesocket(int fd) |
| 63 | 63 |
* \param[in] sock socket descriptor to check |
| 64 | 64 |
* \return 1 if valid, 0 if not valid |
| 65 | 65 |
*/ |
| 66 |
-extern inline int flp_sock_is_valid(flp_sock_t sock) |
|
| 66 |
+static inline int flp_sock_is_valid(flp_sock_t sock) |
|
| 67 | 67 |
{
|
| 68 | 68 |
#ifdef WINDOWS |
| 69 | 69 |
return sock != INVALID_SOCKET; |
| ... | ... |
@@ -77,7 +77,7 @@ extern inline int flp_sock_is_valid(flp_sock_t sock) |
| 77 | 77 |
* \param[in] buf pointer to buffer to place text into |
| 78 | 78 |
* \param[in] buflen size of buffer |
| 79 | 79 |
*/ |
| 80 |
-extern inline void flp_sock_get_last_error(char *buf, size_t buflen) |
|
| 80 |
+static inline void flp_sock_get_last_error(char *buf, size_t buflen) |
|
| 81 | 81 |
{
|
| 82 | 82 |
#ifdef WINDOWS |
| 83 | 83 |
int err = WSAGetLastError(); |
| ... | ... |
@@ -71,7 +71,7 @@ typedef pthread_cond_t flp_thread_cond_t; |
| 71 | 71 |
* \param[in] p_data user data pointer |
| 72 | 72 |
* \return 1 if successful, 0 on error |
| 73 | 73 |
*/ |
| 74 |
-extern inline int flp_thread_create(flp_thread_id_t *p_tid, |
|
| 74 |
+static inline int flp_thread_create(flp_thread_id_t *p_tid, |
|
| 75 | 75 |
FLP_THREAD_FUNC(*func), |
| 76 | 76 |
void * p_data) |
| 77 | 77 |
{
|
| ... | ... |
@@ -89,7 +89,7 @@ extern inline int flp_thread_create(flp_thread_id_t *p_tid, |
| 89 | 89 |
* \brief join a thread |
| 90 | 90 |
* \param[in] tid thread ID |
| 91 | 91 |
*/ |
| 92 |
-extern inline void flp_thread_join(flp_thread_id_t tid) |
|
| 92 |
+static inline void flp_thread_join(flp_thread_id_t tid) |
|
| 93 | 93 |
{
|
| 94 | 94 |
#ifdef WINDOWS |
| 95 | 95 |
WaitForSingleObject(tid, INFINITE); |
| ... | ... |
@@ -104,7 +104,7 @@ extern inline void flp_thread_join(flp_thread_id_t tid) |
| 104 | 104 |
* \param[in] *p_mtx mutex variable |
| 105 | 105 |
* \return 1 if successful, 0 on error |
| 106 | 106 |
*/ |
| 107 |
-extern inline int flp_thread_mutex_init(flp_thread_mutex_t *p_mtx) |
|
| 107 |
+static inline int flp_thread_mutex_init(flp_thread_mutex_t *p_mtx) |
|
| 108 | 108 |
{
|
| 109 | 109 |
#ifdef WINDOWS |
| 110 | 110 |
HANDLE h = CreateMutex(NULL, FALSE, NULL); |
| ... | ... |
@@ -120,7 +120,7 @@ extern inline int flp_thread_mutex_init(flp_thread_mutex_t *p_mtx) |
| 120 | 120 |
* \brief destroy mutex |
| 121 | 121 |
* \param[in] *p_mtx mutex variable |
| 122 | 122 |
*/ |
| 123 |
-extern inline void flp_thread_mutex_destroy(flp_thread_mutex_t *p_mtx) |
|
| 123 |
+static inline void flp_thread_mutex_destroy(flp_thread_mutex_t *p_mtx) |
|
| 124 | 124 |
{
|
| 125 | 125 |
#ifdef WINDOWS |
| 126 | 126 |
CloseHandle(*p_mtx); |
| ... | ... |
@@ -133,7 +133,7 @@ extern inline void flp_thread_mutex_destroy(flp_thread_mutex_t *p_mtx) |
| 133 | 133 |
* \brief lock mutex |
| 134 | 134 |
* \param[in] *p_mtx mutex variable |
| 135 | 135 |
*/ |
| 136 |
-extern inline void flp_thread_mutex_lock(flp_thread_mutex_t *p_mtx) |
|
| 136 |
+static inline void flp_thread_mutex_lock(flp_thread_mutex_t *p_mtx) |
|
| 137 | 137 |
{
|
| 138 | 138 |
#ifdef WINDOWS |
| 139 | 139 |
WaitForSingleObject(*p_mtx, INFINITE); |
| ... | ... |
@@ -146,7 +146,7 @@ extern inline void flp_thread_mutex_lock(flp_thread_mutex_t *p_mtx) |
| 146 | 146 |
* \brief unlock mutex |
| 147 | 147 |
* \param[in] *p_mtx mutex variable |
| 148 | 148 |
*/ |
| 149 |
-extern inline void flp_thread_mutex_unlock(flp_thread_mutex_t *p_mtx) |
|
| 149 |
+static inline void flp_thread_mutex_unlock(flp_thread_mutex_t *p_mtx) |
|
| 150 | 150 |
{
|
| 151 | 151 |
#ifdef WINDOWS |
| 152 | 152 |
ReleaseMutex(*p_mtx); |
| ... | ... |
@@ -160,7 +160,7 @@ extern inline void flp_thread_mutex_unlock(flp_thread_mutex_t *p_mtx) |
| 160 | 160 |
* \param[in] *p_cond conition variable |
| 161 | 161 |
* \return 1 if successful, 0 on error |
| 162 | 162 |
*/ |
| 163 |
-extern inline int flp_thread_cond_init(flp_thread_cond_t *p_cond) |
|
| 163 |
+static inline int flp_thread_cond_init(flp_thread_cond_t *p_cond) |
|
| 164 | 164 |
{
|
| 165 | 165 |
#ifdef WINDOWS |
| 166 | 166 |
HANDLE h = CreateEvent(NULL, FALSE, FALSE, NULL); |
| ... | ... |
@@ -176,7 +176,7 @@ extern inline int flp_thread_cond_init(flp_thread_cond_t *p_cond) |
| 176 | 176 |
* \brief destroy condition |
| 177 | 177 |
* \param[in] *p_cond condition variable |
| 178 | 178 |
*/ |
| 179 |
-extern inline void flp_thread_cond_destroy(flp_thread_cond_t *p_cond) |
|
| 179 |
+static inline void flp_thread_cond_destroy(flp_thread_cond_t *p_cond) |
|
| 180 | 180 |
{
|
| 181 | 181 |
#ifdef WINDOWS |
| 182 | 182 |
CloseHandle(*p_cond); |
| ... | ... |
@@ -189,7 +189,7 @@ extern inline void flp_thread_cond_destroy(flp_thread_cond_t *p_cond) |
| 189 | 189 |
* \brief signal condition |
| 190 | 190 |
* \param[in] *p_cond condition variable |
| 191 | 191 |
*/ |
| 192 |
-extern inline void flp_thread_cond_signal(flp_thread_cond_t *p_cond) |
|
| 192 |
+static inline void flp_thread_cond_signal(flp_thread_cond_t *p_cond) |
|
| 193 | 193 |
{
|
| 194 | 194 |
#ifdef WINDOWS |
| 195 | 195 |
SetEvent(*p_cond); |
| ... | ... |
@@ -203,7 +203,7 @@ extern inline void flp_thread_cond_signal(flp_thread_cond_t *p_cond) |
| 203 | 203 |
* \param[in] *p_cond condition variable |
| 204 | 204 |
* \param[in] *p_mtx mutex variable to unlock while waiting |
| 205 | 205 |
*/ |
| 206 |
-extern inline void flp_thread_cond_wait(flp_thread_cond_t *p_cond, |
|
| 206 |
+static inline void flp_thread_cond_wait(flp_thread_cond_t *p_cond, |
|
| 207 | 207 |
flp_thread_mutex_t *p_mtx) |
| 208 | 208 |
{
|
| 209 | 209 |
#ifdef WINDOWS |
| ... | ... |
@@ -225,7 +225,7 @@ extern inline void flp_thread_cond_wait(flp_thread_cond_t *p_cond, |
| 225 | 225 |
* \param[in] millisecs number of milliseconds to wait at most |
| 226 | 226 |
* \return 0 for condition singnaled, 1 for timeout |
| 227 | 227 |
*/ |
| 228 |
-extern inline int flp_thread_cond_timedwait(flp_thread_cond_t *p_cond, |
|
| 228 |
+static inline int flp_thread_cond_timedwait(flp_thread_cond_t *p_cond, |
|
| 229 | 229 |
flp_thread_mutex_t *p_mtx, |
| 230 | 230 |
struct timeval *p_now, |
| 231 | 231 |
unsigned int millisecs) |
| ... | ... |
@@ -688,7 +688,8 @@ int flp_config_proc_file(flp_display_t *p_display, |
| 688 | 688 |
|
| 689 | 689 |
/* read a line */ |
| 690 | 690 |
line[0] = 0; |
| 691 |
- fgets(line, sizeof (line), file); |
|
| 691 |
+ if (fgets(line, sizeof (line), file) == NULL) |
|
| 692 |
+ break; |
|
| 692 | 693 |
p_lf = strchr(line, '\n'); /* find LF in line in replace it with 0 */ |
| 693 | 694 |
if (p_lf) |
| 694 | 695 |
*p_lf = 0; |
| ... | ... |
@@ -702,7 +703,8 @@ int flp_config_proc_file(flp_display_t *p_display, |
| 702 | 703 |
/* jump over in rest of line */ |
| 703 | 704 |
dummy[0] = 0; |
| 704 | 705 |
while (!feof(file) && !strchr(dummy, '\n')) |
| 705 |
- fgets(dummy, sizeof (dummy), file); |
|
| 706 |
+ if (fgets(dummy, sizeof (dummy), file) == NULL) |
|
| 707 |
+ break; |
|
| 706 | 708 |
} |
| 707 | 709 |
} |
| 708 | 710 |
|
| 709 | 711 |