Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Fix compiler and static analysis warnings #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions src/ConvertUTF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ ConversionResult ConvertUTF16toUTF8 (
target -= bytesToWrite; result = targetExhausted; break;
}
switch (bytesToWrite) { /* note: everything falls through. */
case 4: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
case 4: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6; // Intentional fallthrough
case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6; // Intentional fallthrough
case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6; // Intentional fallthrough
case 1: *--target = (UTF8)(ch | firstByteMark[bytesToWrite]);
}
target += bytesToWrite;
Expand Down Expand Up @@ -299,10 +299,9 @@ static Boolean isLegalUTF8(const UTF8 *source, int length) {
switch (length) {
default: return false;
/* Everything else falls through when "true"... */
case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false; // Intentional fallthrough
case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false; // Intentional fallthrough
case 2: if ((a = (*--srcptr)) > 0xBF) return false;

switch (*source) {
/* no fall-through in this inner switch */
case 0xE0: if (a < 0xA0) return false; break;
Expand All @@ -311,7 +310,7 @@ static Boolean isLegalUTF8(const UTF8 *source, int length) {
case 0xF4: if (a > 0x8F) return false; break;
default: if (a < 0x80) return false;
}

// Intentional fallthrough
case 1: if (*source >= 0x80 && *source < 0xC2) return false;
}
if (*source > 0xF4) return false;
Expand Down Expand Up @@ -355,11 +354,11 @@ ConversionResult ConvertUTF8toUTF16 (
* The cases all fall through. See "Note A" below.
*/
switch (extraBytesToRead) {
case 5: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
case 4: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
case 3: ch += *source++; ch <<= 6;
case 2: ch += *source++; ch <<= 6;
case 1: ch += *source++; ch <<= 6;
case 5: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */ // Intentional fallthrough
case 4: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */ // Intentional fallthrough
case 3: ch += *source++; ch <<= 6; // Intentional fallthrough
case 2: ch += *source++; ch <<= 6; // Intentional fallthrough
case 1: ch += *source++; ch <<= 6; // Intentional fallthrough
case 0: ch += *source++;
}
ch -= offsetsFromUTF8[extraBytesToRead];
Expand Down Expand Up @@ -446,9 +445,9 @@ ConversionResult ConvertUTF32toUTF8 (
target -= bytesToWrite; result = targetExhausted; break;
}
switch (bytesToWrite) { /* note: everything falls through. */
case 4: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
case 4: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6; // Intentional fallthrough
case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6; // Intentional fallthrough
case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6; // Intentional fallthrough
case 1: *--target = (UTF8) (ch | firstByteMark[bytesToWrite]);
}
target += bytesToWrite;
Expand Down Expand Up @@ -481,11 +480,11 @@ ConversionResult ConvertUTF8toUTF32 (
* The cases all fall through. See "Note A" below.
*/
switch (extraBytesToRead) {
case 5: ch += *source++; ch <<= 6;
case 4: ch += *source++; ch <<= 6;
case 3: ch += *source++; ch <<= 6;
case 2: ch += *source++; ch <<= 6;
case 1: ch += *source++; ch <<= 6;
case 5: ch += *source++; ch <<= 6; // Intentional fallthrough
case 4: ch += *source++; ch <<= 6; // Intentional fallthrough
case 3: ch += *source++; ch <<= 6; // Intentional fallthrough
case 2: ch += *source++; ch <<= 6; // Intentional fallthrough
case 1: ch += *source++; ch <<= 6; // Intentional fallthrough
case 0: ch += *source++;
}
ch -= offsetsFromUTF8[extraBytesToRead];
Expand Down
17 changes: 15 additions & 2 deletions src/linenoise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,20 @@ struct PromptBase { // a convenience struct for grouping prompt info
int promptPreviousLen; // help erasing
int promptErrorCode; // error code (invalid UTF-8) or zero

PromptBase() : promptPreviousInputLen(0) {}
PromptBase() :
promptText(0),
promptCharWidths(nullptr),
promptChars(0),
promptBytes(0),
promptExtraLines(0),
promptIndentation(0),
promptLastLinePosition(0),
promptPreviousInputLen(0),
promptCursorRowOffset(0),
promptScreenColumns(0),
promptPreviousLen(0),
promptErrorCode(0)
{}

bool write() {
if (write32(1, promptText.get(), promptBytes) == -1) return false;
Expand Down Expand Up @@ -727,7 +740,7 @@ struct DynamicPrompt : public PromptBase {
int direction; // current search direction, 1=forward, -1=reverse

DynamicPrompt(PromptBase& pi, int initialDirection)
: searchTextLen(0), direction(initialDirection) {
: searchCharWidths(nullptr), searchTextLen(0), direction(initialDirection) {
promptScreenColumns = pi.promptScreenColumns;
promptCursorRowOffset = 0;
Utf32String emptyString(1);
Expand Down