Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-25212] remove warning messages from compilation #4933

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

beyondykk9
Copy link
Contributor

http://jira.cubrid.org/browse/CBRD-25212

We need remove the warning messages from compilation (CUBRID engine build). By doing this, we can prevent potential problems in advance.

The target source code is as follows.

src/base/
src/compat/
src/connection/
src/communication/
src/heaplayers/
src/thread/
src/object/
src/session/
src/jsp/
src/method/
src/parser/
src/query/
src/xasl/

@beyondykk9 beyondykk9 added this to the fig-cake milestone Feb 2, 2024
@beyondykk9 beyondykk9 self-assigned this Feb 2, 2024
@@ -622,7 +622,7 @@ logddl_make_copy_filename (T_APP_NAME app_name, const char *file_full_path, char
const char *name_tmp = NULL;
int retval = 0;

if (file_full_path == NULL || copy_filename == NULL || buf_size < 0)
if (file_full_path == NULL || copy_filename == NULL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to remove the buf_size argument and specify PATH_MAX directly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the buf_size parameter should be kept. The reason is that the size of the string can change.

@@ -658,7 +658,7 @@ logddl_make_copy_dir (T_APP_NAME app_name, char *copy_filename, char *copy_fullp
const char *env_root = NULL;
int retval = 0;

if (copy_filename == NULL || copy_fullpath == NULL || buf_size < 0)
if (copy_filename == NULL || copy_fullpath == NULL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to remove the buf_size argument and specify PATH_MAX directly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the buf_size parameter should be kept. The reason is that the size of the string can change.

@@ -162,7 +162,7 @@ char csql_Scratch_text[SCRATCH_TEXT_LEN];
int csql_Error_code = NO_ERROR;

static char csql_Prompt[100];
static char csql_Prompt_offline[100];
static char csql_Prompt_offline[101];
Copy link
Contributor

@airnet73 airnet73 Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "snprintf (csql_Prompt_offline, sizeof (csql_Prompt_offline) - 1, "!%s", csql_Prompt);" is better than "csql_Prompt_offline[101]". (line 2772)

@@ -2684,6 +2684,8 @@ or_get_oid (OR_BUF * buf, OID * oid)
{
ASSERT_ALIGN (buf->ptr, INT_ALIGNMENT);

OID_SET_NULL (oid);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to the then part of the if statement below because setting the oid fields is done in else part.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I aggree.

@@ -11518,7 +11518,7 @@ tp_value_auto_cast_with_precision_check (const DB_VALUE * src, DB_VALUE * dest,
/* if the numeric's precision is 19 or more, then it can get the bigint enough */
if (desired_domain->type->id == DB_TYPE_NUMERIC && desired_domain->precision < 19)
{
INT64 bigint;
INT64 bigint = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to the default branch of the switch statement below because this is overwritten in other branches.

@@ -3568,7 +3568,7 @@ static int
mr_data_readval_utime (OR_BUF * buf, DB_VALUE * value, TP_DOMAIN * domain, int size, bool copy, char *copy_buf,
int copy_buf_len)
{
DB_UTIME utm;
DB_UTIME utm = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definition should be moved to the else branch of the if statement below because utm is used only in that branch.

@@ -3591,7 +3591,7 @@ static int
mr_data_readval_timestampltz (OR_BUF * buf, DB_VALUE * value, TP_DOMAIN * domain, int size, bool copy, char *copy_buf,
int copy_buf_len)
{
DB_UTIME utm;
DB_UTIME utm = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definition should be moved to the else branch of the if statement below because utm is used only in that branch.

@@ -11607,7 +11607,7 @@ pt_convert_dblink_dml_query (PARSER_CONTEXT * parser, PT_NODE * node,
PT_NODE *list = NULL; /* for insert select list */
PT_NODE *spec, *into_spec = NULL, *upd_spec = NULL, *server;

PARSER_VARCHAR *comment, *dml;
PARSER_VARCHAR *comment = NULL, *dml;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This NULL assignment should be moved to the default branch of the switch statement at line 11726 because in other branches the assignment is overwritten.

@@ -15348,12 +15348,12 @@ do_supplemental_statement (PARSER_CONTEXT * parser, PT_NODE * statement, RESERVE

if (cls_info[i]->objtype == CDC_TABLE)
{
strncpy (drop_stmt, drop_prefix, strlen (drop_prefix));
strncpy (drop_stmt, drop_prefix, strlen (drop_prefix) + 1);
Copy link
Contributor

@hyunikn hyunikn Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strncpy(dst, src, strlen(src) + 1) is equivalent to strcpy(dst, src) and can be simplified to the latter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I habitually use strncpy inside this function, but it would be better to replace it with strcpy.
If we go a little further,
A more desirable solution is possible by changing the order of the process of finding the length after copying.

strncpy (drop_stmt, drop_prefix, strlen (drop_prefix) + 1);
drop_copied_length = strlen (drop_prefix);

Replace the form above as below (there is a small gain in performance)

drop_copied_length = strlen (drop_prefix);
memcpy (drop_stmt, drop_prefix, len + 1);

@@ -515,7 +515,7 @@ ini_parse_line (char *input_line, char *section, char *key, char *value)
leading_char = section[0];
if (leading_char == '@' || leading_char == '%')
{
sprintf (section, "%c%s", leading_char, ini_str_trim (section + 1));
snprintf (section, INI_BUFSIZ + 2, "%c%s", leading_char, ini_str_trim (section + 1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size of the section is (INI_BUFSIZ + 1).

@@ -255,7 +255,7 @@ get_class_mops_from_file (const char *input_filename, MOP ** class_list, int *nu
goto end;
}

strncpy (class_names[i], buffer, len);
strncpy (class_names[i], buffer, len + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to copy with a size of "len+1"?
If you decide to modify it anyway, I recommend doing it as follows.

memcpy (class_names[i], buffer, len);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 is necessary because class_names[i] must end with a terminating zero. Isn't it?
Note that len is strlen(buffer).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hyunikn
In the code, '\0' is filled with the substitution statement immediately below.
class_names[i][len] = 0;

@@ -493,7 +493,7 @@ namespace cubmethod
fprintf (stdout, "tuple_count: %d\n", tuple_count);
fprintf (stdout, "ins_oid (%d, %d, %d)\n", ins_oid.pageid, ins_oid.slotid, ins_oid.volid);
fprintf (stdout, "include_oid: %d\n", include_oid);
fprintf (stdout, "query_id: %lld\n", query_id);
fprintf (stdout, "query_id: %ud\n", (unsigned int)query_id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

query_id is of type UINTPTR.
This is defined differently depending on define.
Therefore, if you do it like below, you will be able to see the warning again even if the type changes in the future.

fprintf (stdout, "query_id: %ud\n", query_id);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It must be %u rather than %ud.
Note that the following code prints '123d'

#include <stdio.h>

int
main() {
    printf("%ud\n", 123);
}

@@ -1149,8 +1148,9 @@ xbtree_load_index (THREAD_ENTRY * thread_p, BTID * btid, const char *bt_name, TP
pr_clear_value (&load_args->current_key);

BTID_SET_NULL (btid);
if (xbtree_add_index (thread_p, btid, key_type, &class_oids[0], attr_ids[0], unique_pk, sort_args->n_oids,
sort_args->n_nulls, load_args->n_keys, btid_int.deduplicate_key_idx) == NULL)
if (xbtree_add_index (thread_p, btid, key_type, &class_oids[0], attr_ids[0], unique_pk, (INT64) sort_args->n_oids,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I should change the member variable of sort_args from int to INT64?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants