Skip to content

Commit 6653206

Browse files
committed
Fixed compiler warnings
- Replace strncpy() with strmake() to ensure things are \0 terminated - Initialized some variables that caused compiler warnings - Increased buffer that caused warnings from strncpy One warning from InnoDB, others from Connect.
1 parent 6e282e7 commit 6653206

File tree

6 files changed

+32
-29
lines changed

6 files changed

+32
-29
lines changed

storage/connect/filamdbf.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#define NO_FUNC
5656
#include "plgcnx.h" // For DB types
5757
#include "resource.h"
58+
#include "m_string.h" // For strmake
5859

5960
/****************************************************************************/
6061
/* Definitions. */
@@ -732,7 +733,7 @@ bool DBFFAM::AllocateBuffer(PGLOBAL g)
732733
return true;
733734
} // endswitch c
734735

735-
strncpy(descp->Name, cdp->GetName(), 11);
736+
strmake(descp->Name, cdp->GetName(), sizeof(descp->Name)-1);
736737
descp->Type = c;
737738
descp->Length = (uchar)cdp->GetLong();
738739
} // endif Flags

storage/connect/jsonudf.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <mysqld.h>
1212
#include <mysql.h>
1313
#include <sql_error.h>
14-
#include <stdio.h>
14+
#include <m_string.h>
1515

1616
#include "jsonudf.h"
1717

@@ -1475,16 +1475,16 @@ static PBSON MakeBinResult(PGLOBAL g, UDF_ARGS *args, PJSON top, ulong len, int
14751475

14761476
if ((bsnp->Filename = (char*)args->args[0])) {
14771477
bsnp->Filename = MakePSZ(g, args, 0);
1478-
strncpy(bsnp->Msg, bsnp->Filename, BMX);
1478+
strmake(bsnp->Msg, bsnp->Filename, BMX-1);
14791479
} else
1480-
strncpy(bsnp->Msg, "null filename", BMX);
1480+
strmake(bsnp->Msg, "null filename", BMX-1);
14811481

14821482
} else if (IsJson(args, 0) == 3) {
14831483
PBSON bsp = (PBSON)args->args[0];
14841484

14851485
if (bsp->Filename) {
14861486
bsnp->Filename = bsp->Filename;
1487-
strncpy(bsnp->Msg, bsp->Filename, BMX);
1487+
strmake(bsnp->Msg, bsp->Filename, BMX-1);
14881488
bsnp->Pretty = bsp->Pretty;
14891489
} else
14901490
strcpy(bsnp->Msg, "Json Binary item");
@@ -4758,7 +4758,7 @@ char *jbin_array(UDF_INIT *initid, UDF_ARGS *args, char *result,
47584758
bsp = NULL;
47594759

47604760
if (!bsp && (bsp = JbinAlloc(g, args, initid->max_length, NULL)))
4761-
strncpy(bsp->Msg, g->Message, BMX);
4761+
strmake(bsp->Msg, g->Message, BMX-1);
47624762

47634763
// Keep result of constant function
47644764
g->Xchk = (initid->const_item) ? bsp : NULL;
@@ -4829,7 +4829,7 @@ char *jbin_array_add_values(UDF_INIT *initid, UDF_ARGS *args, char *result,
48294829

48304830
} else
48314831
if ((bsp = JbinAlloc(g, args, initid->max_length, NULL)))
4832-
strncpy(bsp->Msg, g->Message, BMX);
4832+
strmake(bsp->Msg, g->Message, BMX-1);
48334833

48344834
// Keep result of constant function
48354835
g->Xchk = (initid->const_item) ? bsp : NULL;
@@ -5051,7 +5051,7 @@ char *jbin_object(UDF_INIT *initid, UDF_ARGS *args, char *result,
50515051

50525052
} else
50535053
if ((bsp = JbinAlloc(g, args, initid->max_length, NULL)))
5054-
strncpy(bsp->Msg, g->Message, BMX);
5054+
strmake(bsp->Msg, g->Message, BMX-1);
50555055

50565056
// Keep result of constant function
50575057
g->Xchk = (initid->const_item) ? bsp : NULL;
@@ -5107,7 +5107,7 @@ char *jbin_object_nonull(UDF_INIT *initid, UDF_ARGS *args, char *result,
51075107

51085108
} else
51095109
if ((bsp = JbinAlloc(g, args, initid->max_length, NULL)))
5110-
strncpy(bsp->Msg, g->Message, BMX);
5110+
strmake(bsp->Msg, g->Message, BMX-1);
51115111

51125112
// Keep result of constant function
51135113
g->Xchk = (initid->const_item) ? bsp : NULL;
@@ -5166,7 +5166,7 @@ char *jbin_object_key(UDF_INIT *initid, UDF_ARGS *args, char *result,
51665166

51675167
} else
51685168
if ((bsp = JbinAlloc(g, args, initid->max_length, NULL)))
5169-
strncpy(bsp->Msg, g->Message, BMX);
5169+
strmake(bsp->Msg, g->Message, BMX-1);
51705170

51715171
// Keep result of constant function
51725172
g->Xchk = (initid->const_item) ? bsp : NULL;

storage/connect/tabxml.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
/* Include required compiler header files. */
1313
/***********************************************************************/
1414
#include "my_global.h"
15-
#include <stdio.h>
15+
#include <m_string.h>
1616
#include <fcntl.h>
17-
#include <errno.h>
1817
#if defined(__WIN__)
1918
#include <io.h>
2019
#include <winsock2.h>
@@ -252,10 +251,11 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info)
252251

253252
more:
254253
if (vp->atp) {
255-
size_t z = sizeof(colname) - 1;
256-
strncpy(colname, vp->atp->GetName(g), z);
257-
colname[z] = 0;
258-
strncat(xcol->Name, colname, XLEN(xcol->Name));
254+
size_t z = sizeof(colname) - 1;
255+
size_t xlen= strlen(xcol->Name);
256+
strmake(colname, vp->atp->GetName(g), z);
257+
strmake(xcol->Name + xlen, colname,
258+
sizeof(xcol->Name) - 1 - xlen);
259259

260260
switch (vp->atp->GetText(g, buf, sizeof(buf))) {
261261
case RC_INFO:
@@ -272,11 +272,13 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info)
272272
strncat(fmt, colname, XLEN(fmt));
273273

274274
} else {
275+
size_t xlen;
275276
if (tdp->Usedom && node->GetType() != 1)
276277
continue;
277278

278-
strncpy(colname, node->GetName(g), sizeof(colname));
279-
strncat(xcol->Name, colname, XLEN(xcol->Name));
279+
xlen= strlen(xcol->Name);
280+
strmake(colname, node->GetName(g), sizeof(colname)-1);
281+
strmake(xcol->Name + xlen, colname, sizeof(xcol->Name) - 1 - xlen);
280282

281283
if (j)
282284
strncat(fmt, colname, XLEN(fmt));

storage/innobase/handler/i_s.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5127,7 +5127,7 @@ i_s_sys_tables_fill_table_stats(
51275127

51285128
while (rec) {
51295129
const char* err_msg;
5130-
dict_table_t* table_rec;
5130+
dict_table_t* table_rec= 0;
51315131

51325132
mtr.commit();
51335133
/* Fetch the dict_table_t structure corresponding to

storage/mroonga/vendor/groonga/lib/ts/ts_expr_parser.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ grn_ts_expr_parser_tokenize_start(grn_ctx *ctx, grn_ts_expr_parser *parser,
360360
grn_ts_str str, grn_ts_expr_token **token)
361361
{
362362
grn_ts_str token_str = { str.ptr, 0 };
363-
grn_ts_expr_start_token *new_token;
363+
grn_ts_expr_start_token *new_token= 0;
364364
grn_rc rc = grn_ts_expr_start_token_open(ctx, token_str, &new_token);
365365
if (rc != GRN_SUCCESS) {
366366
return rc;
@@ -375,7 +375,7 @@ grn_ts_expr_parser_tokenize_end(grn_ctx *ctx, grn_ts_expr_parser *parser,
375375
grn_ts_str str, grn_ts_expr_token **token)
376376
{
377377
grn_ts_str token_str = { str.ptr, 0 };
378-
grn_ts_expr_end_token *new_token;
378+
grn_ts_expr_end_token *new_token= 0;
379379
grn_rc rc = grn_ts_expr_end_token_open(ctx, token_str, &new_token);
380380
if (rc != GRN_SUCCESS) {
381381
return rc;
@@ -393,7 +393,7 @@ grn_ts_expr_parser_tokenize_number(grn_ctx *ctx, grn_ts_expr_parser *parser,
393393
grn_rc rc;
394394
grn_ts_int int_value;
395395
grn_ts_str token_str;
396-
grn_ts_expr_const_token *new_token;
396+
grn_ts_expr_const_token *new_token= 0;
397397

398398
int_value = strtol(str.ptr, &end, 0);
399399
if ((end != str.ptr) && (*end != '.') && (*end != 'e')) {
@@ -442,7 +442,7 @@ grn_ts_expr_parser_tokenize_text(grn_ctx *ctx, grn_ts_expr_parser *parser,
442442
size_t i, n_escapes = 0;
443443
grn_rc rc;
444444
grn_ts_str token_str;
445-
grn_ts_expr_const_token *new_token;
445+
grn_ts_expr_const_token *new_token= 0;
446446
for (i = 1; i < str.size; i++) {
447447
if (str.ptr[i] == '\\') {
448448
i++;
@@ -504,7 +504,7 @@ grn_ts_expr_parser_tokenize_name(grn_ctx *ctx, grn_ts_expr_parser *parser,
504504
token_str.size = i;
505505

506506
if (grn_ts_str_is_bool(token_str)) {
507-
grn_ts_expr_const_token *new_token;
507+
grn_ts_expr_const_token *new_token= 0;
508508
grn_rc rc = grn_ts_expr_const_token_open(ctx, token_str, &new_token);
509509
if (rc != GRN_SUCCESS) {
510510
return rc;
@@ -527,7 +527,7 @@ grn_ts_expr_parser_tokenize_bridge(grn_ctx *ctx, grn_ts_expr_parser *parser,
527527
grn_ts_str str, grn_ts_expr_token **token)
528528
{
529529
grn_ts_str token_str = { str.ptr, 1 };
530-
grn_ts_expr_bridge_token *new_token;
530+
grn_ts_expr_bridge_token *new_token= 0;
531531
grn_rc rc = grn_ts_expr_bridge_token_open(ctx, token_str, &new_token);
532532
if (rc != GRN_SUCCESS) {
533533
return rc;
@@ -543,7 +543,7 @@ grn_ts_expr_parser_tokenize_bracket(grn_ctx *ctx, grn_ts_expr_parser *parser,
543543
grn_ts_expr_token **token)
544544
{
545545
grn_ts_str token_str = { str.ptr, 1 };
546-
grn_ts_expr_bracket_token *new_token;
546+
grn_ts_expr_bracket_token *new_token= 0;
547547
grn_rc rc = grn_ts_expr_bracket_token_open(ctx, token_str, &new_token);
548548
if (rc != GRN_SUCCESS) {
549549
return rc;
@@ -567,7 +567,7 @@ grn_ts_expr_parser_tokenize_sign(grn_ctx *ctx, grn_ts_expr_parser *parser,
567567
grn_ts_op_type op_type;
568568
grn_ts_str token_str = { str.ptr, 1 };
569569
grn_ts_expr_token *prev_token = parser->tokens[parser->n_tokens - 1];
570-
grn_ts_expr_op_token *new_token;
570+
grn_ts_expr_op_token *new_token= 0;
571571
switch (prev_token->type) {
572572
case GRN_TS_EXPR_START_TOKEN:
573573
case GRN_TS_EXPR_OP_TOKEN: {
@@ -626,7 +626,7 @@ grn_ts_expr_parser_tokenize_op(grn_ctx *ctx, grn_ts_expr_parser *parser,
626626
grn_rc rc = GRN_SUCCESS;
627627
grn_ts_str token_str = str;
628628
grn_ts_op_type op_type;
629-
grn_ts_expr_op_token *new_token;
629+
grn_ts_expr_op_token *new_token= 0;
630630
switch (str.ptr[0]) {
631631
case '+': case '-': {
632632
return grn_ts_expr_parser_tokenize_sign(ctx, parser, str, token);

storage/mroonga/vendor/groonga/vendor/plugins/groonga-normalizer-mysql/normalizers/mysql.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ normalize(grn_ctx *ctx, grn_obj *string,
439439
normalized[normalized_length_in_bytes] = '\0';
440440

441441
if (rest_length > 0) {
442-
char buffer[SNIPPET_BUFFER_SIZE];
442+
char buffer[SNIPPET_BUFFER_SIZE+1];
443443
GRN_PLUGIN_LOG(ctx, GRN_LOG_DEBUG,
444444
"[normalizer][%s] failed to normalize at %u byte: %s",
445445
normalizer_type_label,

0 commit comments

Comments
 (0)