Skip to content

Commit 773b32a

Browse files
committed
removed use of variable-length arrays
1 parent 9786df2 commit 773b32a

File tree

7 files changed

+16
-18
lines changed

7 files changed

+16
-18
lines changed

src/objects/database/checkpoint.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ NAN_METHOD(Database::Checkpoint) {
2222

2323
if (status != SQLITE_OK) {
2424
CONCAT2(message, "SQLite: ", sqlite3_errmsg(db->db_handle));
25-
return Nan::ThrowError(message);
25+
return Nan::ThrowError(message.c_str());
2626
}
2727

2828
if (checkpointed_frames < 0 || total_frames < 0) {

src/objects/database/create-statement.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ NAN_METHOD(Database::CreateStatement) {
3131
// Validates the newly created statement.
3232
if (status != SQLITE_OK) {
3333
CONCAT3(message, "Failed to construct SQL statement (", sqlite3_errmsg(db->db_handle), ").");
34-
return Nan::ThrowError(message);
34+
return Nan::ThrowError(message.c_str());
3535
}
3636
if (stmt->st_handle == NULL) {
3737
return Nan::ThrowTypeError("The supplied SQL string contains no statements.");

src/objects/database/create-transaction.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ NAN_METHOD(Database::CreateTransaction) {
6767
// Validates the newly created statement.
6868
if (status != SQLITE_OK) {
6969
CONCAT3(message, "Failed to construct SQL statement (", sqlite3_errmsg(db->db_handle), ").");
70-
return Nan::ThrowError(message);
70+
return Nan::ThrowError(message.c_str());
7171
}
7272
if (trans->handles[i] == NULL) {
7373
return Nan::ThrowTypeError("One of the supplied SQL strings contains no statements.");

src/objects/database/pragma.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ NAN_METHOD(Database::Pragma) {
4848
if (err != NULL) {
4949
CONCAT2(message, "SQLite: ", err);
5050
sqlite3_free(err);
51-
return Nan::ThrowError(message);
51+
return Nan::ThrowError(message.c_str());
5252
}
5353
sqlite3_free(err);
5454

src/util/macros.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <sys/types.h>
55
#include <cmath>
6-
#include <cstring>
6+
#include <string>
77
#include <sqlite3.h>
88
#include <nan.h>
99
#include "strlcpy.h"
@@ -33,20 +33,18 @@ inline bool IS_32BIT_INT(double num) {
3333
return floor(num) == num && num < 2147483648 && num >= -2147483648;
3434
}
3535

36-
// Creates a stack-allocated buffer of the concatenation of 2 well-formed
36+
// Creates a stack-allocated std:string of the concatenation of 2 well-formed
3737
// C-strings.
3838
#define CONCAT2(result, a, b) \
39-
char result[strlen(a) + strlen(b) + 1]; \
40-
strcpy(result, a); \
41-
strcat(result, b);
39+
std::string result(a); \
40+
result += b;
4241

43-
// Creates a stack-allocated buffer of the concatenation of 3 well-formed
42+
// Creates a stack-allocated std:string of the concatenation of 3 well-formed
4443
// C-strings.
4544
#define CONCAT3(result, a, b, c) \
46-
char result[strlen(a) + strlen(b) + strlen(c) + 1]; \
47-
strcpy(result, a); \
48-
strcat(result, b); \
49-
strcat(result, c);
45+
std::string result(a); \
46+
result += b; \
47+
result += c;
5048

5149
// Given a v8::Object and a C-string method name, retrieves the v8::Function
5250
// representing that method. If the getter throws, or if the property is not a
@@ -203,7 +201,7 @@ inline bool IS_32BIT_INT(double num) {
203201
#define QUERY_THROW_STAY(obj, UNBIND_MACRO, error_out) \
204202
CONCAT2(_error_message, "SQLite: ", error_out); \
205203
QUERY_CLEANUP(obj, UNBIND_MACRO); \
206-
Nan::ThrowError(_error_message);
204+
Nan::ThrowError(_error_message.c_str());
207205

208206
// The macro-instruction that runs after a failed SQLite request.
209207
#define QUERY_THROW(obj, UNBIND_MACRO, error_out) \

src/workers/close.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void CloseWorker::HandleErrorCallback() {
3737
CONCAT2(message, "SQLite: ", ErrorMessage());
3838
v8::Local<v8::Value> args[2] = {
3939
NEW_INTERNAL_STRING_FAST("close"),
40-
Nan::Error(message)
40+
Nan::Error(message.c_str())
4141
};
4242

4343
EMIT_EVENT(database, 2, args);

src/workers/open.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void OpenWorker::Execute() {
2727

2828
assert(sqlite3_db_mutex(db->db_handle) == NULL);
2929
sqlite3_busy_timeout(db->db_handle, 5000);
30-
sqlite3_limit(db->db_handle, SQLITE_LIMIT_LENGTH, std::min(max_buffer_size, max_string_size));
30+
sqlite3_limit(db->db_handle, SQLITE_LIMIT_LENGTH, (std::min)(max_buffer_size, max_string_size));
3131
sqlite3_limit(db->db_handle, SQLITE_LIMIT_SQL_LENGTH, max_string_size);
3232
sqlite3_limit(db->db_handle, SQLITE_LIMIT_COLUMN, 0x7fffffff);
3333
sqlite3_limit(db->db_handle, SQLITE_LIMIT_COMPOUND_SELECT, 0x7fffffff);
@@ -66,7 +66,7 @@ void OpenWorker::HandleErrorCallback() {
6666
CONCAT2(message, "SQLite: ", ErrorMessage());
6767
v8::Local<v8::Value> args[2] = {
6868
NEW_INTERNAL_STRING_FAST("close"),
69-
Nan::Error(message)
69+
Nan::Error(message.c_str())
7070
};
7171

7272
EMIT_EVENT(database, 2, args);

0 commit comments

Comments
 (0)