mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-21 03:21:16 -03:00
lint: constant if expression
This commit is contained in:
@@ -196,15 +196,14 @@ static wcstring str2wcs_internal(const char *in, const size_t in_len) {
|
|||||||
// Protect against broken mbrtowc() implementations which attempt to encode UTF-8
|
// Protect against broken mbrtowc() implementations which attempt to encode UTF-8
|
||||||
// sequences longer than four bytes (e.g., OS X Snow Leopard).
|
// sequences longer than four bytes (e.g., OS X Snow Leopard).
|
||||||
use_encode_direct = true;
|
use_encode_direct = true;
|
||||||
} else if (sizeof(wchar_t) == 2 && (in[in_pos] & 0xF8) == 0xF0) {
|
} else if (sizeof(wchar_t) == 2 && //!OCLINT(constant if expression)
|
||||||
|
(in[in_pos] & 0xF8) == 0xF0) {
|
||||||
// Assume we are in a UTF-16 environment (e.g., Cygwin) using a UTF-8 encoding.
|
// Assume we are in a UTF-16 environment (e.g., Cygwin) using a UTF-8 encoding.
|
||||||
// The bits set check will be true for a four byte UTF-8 sequence that requires
|
// The bits set check will be true for a four byte UTF-8 sequence that requires
|
||||||
// two UTF-16 chars. Something that doesn't work with our simple use of mbrtowc().
|
// two UTF-16 chars. Something that doesn't work with our simple use of mbrtowc().
|
||||||
use_encode_direct = true;
|
use_encode_direct = true;
|
||||||
} else {
|
} else {
|
||||||
ret = mbrtowc(&wc, &in[in_pos], in_len - in_pos, &state);
|
ret = mbrtowc(&wc, &in[in_pos], in_len - in_pos, &state);
|
||||||
// fprintf(stderr, "WTF in_pos %d ret %d\n", in_pos, ret);
|
|
||||||
|
|
||||||
// Determine whether to encode this character with our crazy scheme.
|
// Determine whether to encode this character with our crazy scheme.
|
||||||
if (wc >= ENCODE_DIRECT_BASE && wc < ENCODE_DIRECT_BASE + 256) {
|
if (wc >= ENCODE_DIRECT_BASE && wc < ENCODE_DIRECT_BASE + 256) {
|
||||||
use_encode_direct = true;
|
use_encode_direct = true;
|
||||||
@@ -219,7 +218,8 @@ static wcstring str2wcs_internal(const char *in, const size_t in_len) {
|
|||||||
} else if (ret > in_len - in_pos) {
|
} else if (ret > in_len - in_pos) {
|
||||||
// Other error codes? Terrifying, should never happen.
|
// Other error codes? Terrifying, should never happen.
|
||||||
use_encode_direct = true;
|
use_encode_direct = true;
|
||||||
} else if (sizeof(wchar_t) == 2 && wc >= 0xD800 && wc <= 0xDFFF) {
|
} else if (sizeof(wchar_t) == 2 && wc >= 0xD800 && //!OCLINT(constant if expression)
|
||||||
|
wc <= 0xDFFF) {
|
||||||
// If we get a surrogate pair char on a UTF-16 system (e.g., Cygwin) then
|
// If we get a surrogate pair char on a UTF-16 system (e.g., Cygwin) then
|
||||||
// it's guaranteed the UTF-8 decoding is wrong so use direct encoding.
|
// it's guaranteed the UTF-8 decoding is wrong so use direct encoding.
|
||||||
use_encode_direct = true;
|
use_encode_direct = true;
|
||||||
@@ -227,24 +227,20 @@ static wcstring str2wcs_internal(const char *in, const size_t in_len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (use_encode_direct) {
|
if (use_encode_direct) {
|
||||||
// fprintf(stderr, "WTF use_encode_direct\n");
|
|
||||||
wc = ENCODE_DIRECT_BASE + (unsigned char)in[in_pos];
|
wc = ENCODE_DIRECT_BASE + (unsigned char)in[in_pos];
|
||||||
result.push_back(wc);
|
result.push_back(wc);
|
||||||
in_pos++;
|
in_pos++;
|
||||||
memset(&state, 0, sizeof state);
|
memset(&state, 0, sizeof state);
|
||||||
} else if (ret == 0) {
|
} else if (ret == 0) { // embedded null byte!
|
||||||
// fprintf(stderr, "WTF null byte\n");
|
|
||||||
// Embedded null byte!
|
|
||||||
result.push_back(L'\0');
|
result.push_back(L'\0');
|
||||||
in_pos++;
|
in_pos++;
|
||||||
memset(&state, 0, sizeof state);
|
memset(&state, 0, sizeof state);
|
||||||
} else {
|
} else { // normal case
|
||||||
// fprintf(stderr, "WTF null byte\n");
|
|
||||||
// Normal case.
|
|
||||||
result.push_back(wc);
|
result.push_back(wc);
|
||||||
in_pos += ret;
|
in_pos += ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,6 @@
|
|||||||
#define IO_SERVICE_MAIN_THREAD_REQUEST_QUEUE 99
|
#define IO_SERVICE_MAIN_THREAD_REQUEST_QUEUE 99
|
||||||
#define IO_SERVICE_RESULT_QUEUE 100
|
#define IO_SERVICE_RESULT_QUEUE 100
|
||||||
|
|
||||||
#define IOTHREAD_LOG if (0)
|
|
||||||
|
|
||||||
static void iothread_service_main_thread_requests(void);
|
static void iothread_service_main_thread_requests(void);
|
||||||
static void iothread_service_result_queue();
|
static void iothread_service_result_queue();
|
||||||
|
|
||||||
@@ -120,7 +118,7 @@ static void *iothread_worker(void *unused) {
|
|||||||
scoped_lock locker(s_spawn_queue_lock);
|
scoped_lock locker(s_spawn_queue_lock);
|
||||||
struct SpawnRequest_t *req;
|
struct SpawnRequest_t *req;
|
||||||
while ((req = dequeue_spawn_request()) != NULL) {
|
while ((req = dequeue_spawn_request()) != NULL) {
|
||||||
IOTHREAD_LOG fprintf(stderr, "pthread %p dequeued %p\n", this_thread(), req);
|
debug(5, "pthread %p dequeued %p\n", this_thread(), req);
|
||||||
// Unlock the queue while we execute the request.
|
// Unlock the queue while we execute the request.
|
||||||
locker.unlock();
|
locker.unlock();
|
||||||
|
|
||||||
@@ -153,7 +151,7 @@ static void *iothread_worker(void *unused) {
|
|||||||
assert(s_active_thread_count > 0);
|
assert(s_active_thread_count > 0);
|
||||||
s_active_thread_count -= 1;
|
s_active_thread_count -= 1;
|
||||||
|
|
||||||
IOTHREAD_LOG fprintf(stderr, "pthread %p exiting\n", this_thread());
|
debug(5, "pthread %p exiting\n", this_thread());
|
||||||
// We're done.
|
// We're done.
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -175,7 +173,7 @@ static void iothread_spawn() {
|
|||||||
|
|
||||||
// We will never join this thread.
|
// We will never join this thread.
|
||||||
VOMIT_ON_FAILURE(pthread_detach(thread));
|
VOMIT_ON_FAILURE(pthread_detach(thread));
|
||||||
IOTHREAD_LOG fprintf(stderr, "pthread %p spawned\n", (void *)(intptr_t)thread);
|
debug(5, "pthread %p spawned\n", (void *)(intptr_t)thread);
|
||||||
// Restore our sigmask.
|
// Restore our sigmask.
|
||||||
VOMIT_ON_FAILURE(pthread_sigmask(SIG_SETMASK, &saved_set, NULL));
|
VOMIT_ON_FAILURE(pthread_sigmask(SIG_SETMASK, &saved_set, NULL));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -432,11 +432,8 @@ const production_t *parse_productions::production_for_token(parse_token_type_t n
|
|||||||
const parse_token_t &input1,
|
const parse_token_t &input1,
|
||||||
const parse_token_t &input2,
|
const parse_token_t &input2,
|
||||||
parse_node_tag_t *out_tag) {
|
parse_node_tag_t *out_tag) {
|
||||||
const bool log_it = false;
|
debug(5, "Resolving production for %ls with input token <%ls>\n",
|
||||||
if (log_it) {
|
token_type_description(node_type), input1.describe().c_str());
|
||||||
fprintf(stderr, "Resolving production for %ls with input token <%ls>\n",
|
|
||||||
token_type_description(node_type), input1.describe().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch the function to resolve the list of productions.
|
// Fetch the function to resolve the list of productions.
|
||||||
const production_t *(*resolver)(const parse_token_t &input1, const parse_token_t &input2,
|
const production_t *(*resolver)(const parse_token_t &input1, const parse_token_t &input2,
|
||||||
@@ -500,9 +497,9 @@ const production_t *parse_productions::production_for_token(parse_token_type_t n
|
|||||||
PARSE_ASSERT(resolver != NULL);
|
PARSE_ASSERT(resolver != NULL);
|
||||||
|
|
||||||
const production_t *result = resolver(input1, input2, out_tag);
|
const production_t *result = resolver(input1, input2, out_tag);
|
||||||
if (result == NULL && log_it) {
|
if (result == NULL) {
|
||||||
fprintf(stderr, "Node type '%ls' has no production for input '%ls' (in %s)\n",
|
debug(5, "Node type '%ls' has no production for input '%ls' (in %s)\n",
|
||||||
token_type_description(node_type), input1.describe().c_str(), __FUNCTION__);
|
token_type_description(node_type), input1.describe().c_str(), __FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ size_t utf8_to_wchar(const char *in, size_t insize, std::wstring *out, int flags
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t result;
|
size_t result;
|
||||||
if (sizeof(wchar_t) == sizeof(utf8_wchar_t)) {
|
if (sizeof(wchar_t) == sizeof(utf8_wchar_t)) { //!OCLINT(constant if expression)
|
||||||
result = utf8_to_wchar_internal(in, insize, reinterpret_cast<utf8_wstring_t *>(out), flags);
|
result = utf8_to_wchar_internal(in, insize, reinterpret_cast<utf8_wstring_t *>(out), flags);
|
||||||
} else if (out == NULL) {
|
} else if (out == NULL) {
|
||||||
result = utf8_to_wchar_internal(in, insize, NULL, flags);
|
result = utf8_to_wchar_internal(in, insize, NULL, flags);
|
||||||
@@ -102,7 +102,7 @@ size_t wchar_to_utf8(const wchar_t *in, size_t insize, char *out, size_t outsize
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t result;
|
size_t result;
|
||||||
if (sizeof(wchar_t) == sizeof(utf8_wchar_t)) {
|
if (sizeof(wchar_t) == sizeof(utf8_wchar_t)) { //!OCLINT(constant if expression)
|
||||||
result = wchar_to_utf8_internal(reinterpret_cast<const utf8_wchar_t *>(in), insize, out,
|
result = wchar_to_utf8_internal(reinterpret_cast<const utf8_wchar_t *>(in), insize, out,
|
||||||
outsize, flags);
|
outsize, flags);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user