summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
Diffstat (limited to 'mysys')
-rw-r--r--mysys/hash.c19
-rw-r--r--mysys/md5.c2
-rw-r--r--mysys/mf_keycache.c11
-rw-r--r--mysys/my_conio.c7
-rw-r--r--mysys/my_init.c36
-rw-r--r--mysys/my_seek.c1
-rw-r--r--mysys/my_symlink2.c2
-rw-r--r--mysys/my_thr_init.c36
8 files changed, 89 insertions, 25 deletions
diff --git a/mysys/hash.c b/mysys/hash.c
index 0c949b3a0d8..9e8404248eb 100644
--- a/mysys/hash.c
+++ b/mysys/hash.c
@@ -570,6 +570,25 @@ my_bool hash_update(HASH *hash,byte *record,byte *old_key,uint old_key_length)
previous->next=pos->next; /* unlink pos */
/* Move data to correct position */
+ if (new_index == empty)
+ {
+ /*
+ At this point record is unlinked from the old chain, thus it holds
+ random position. By the chance this position is equal to position
+ for the first element in the new chain. That means updated record
+ is the only record in the new chain.
+ */
+ if (empty != idx)
+ {
+ /*
+ Record was moved while unlinking it from the old chain.
+ Copy data to a new position.
+ */
+ data[empty]= org_link;
+ }
+ data[empty].next= NO_RECORD;
+ DBUG_RETURN(0);
+ }
pos=data+new_index;
new_pos_index=hash_rec_mask(hash,pos,blength,records);
if (new_index != new_pos_index)
diff --git a/mysys/md5.c b/mysys/md5.c
index a88fb279a0b..0945f9ce5f4 100644
--- a/mysys/md5.c
+++ b/mysys/md5.c
@@ -45,7 +45,7 @@ documentation and/or software.
#include <my_global.h>
#include <m_string.h>
-#include "md5.h"
+#include "my_md5.h"
/* Constants for MD5Transform routine. */
diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c
index 87f136dbf81..af910678a1f 100644
--- a/mysys/mf_keycache.c
+++ b/mysys/mf_keycache.c
@@ -173,7 +173,7 @@ static void test_key_cache(KEY_CACHE *keycache,
#endif
#define KEYCACHE_HASH(f, pos) \
-(((ulong) ((pos) >> keycache->key_cache_shift)+ \
+(((ulong) ((pos) / keycache->key_cache_block_size) + \
(ulong) (f)) & (keycache->hash_entries-1))
#define FILE_HASH(f) ((uint) (f) & (CHANGED_BLOCKS_HASH-1))
@@ -329,7 +329,6 @@ int init_key_cache(KEY_CACHE *keycache, uint key_cache_block_size,
keycache->key_cache_mem_size= use_mem;
keycache->key_cache_block_size= key_cache_block_size;
- keycache->key_cache_shift= my_bit_log2(key_cache_block_size);
DBUG_PRINT("info", ("key_cache_block_size: %u",
key_cache_block_size));
@@ -352,7 +351,7 @@ int init_key_cache(KEY_CACHE *keycache, uint key_cache_block_size,
ALIGN_SIZE(hash_links * sizeof(HASH_LINK)) +
ALIGN_SIZE(sizeof(HASH_LINK*) *
keycache->hash_entries))) +
- ((ulong) blocks << keycache->key_cache_shift) > use_mem)
+ ((ulong) blocks * keycache->key_cache_block_size) > use_mem)
blocks--;
/* Allocate memory for cache page buffers */
if ((keycache->block_mem=
@@ -1807,7 +1806,7 @@ byte *key_cache_read(KEY_CACHE *keycache,
uint status;
int page_st;
- offset= (uint) (filepos & (keycache->key_cache_block_size-1));
+ offset= (uint) (filepos % keycache->key_cache_block_size);
/* Read data in key_cache_block_size increments */
do
{
@@ -1946,7 +1945,7 @@ int key_cache_insert(KEY_CACHE *keycache,
int error;
uint offset;
- offset= (uint) (filepos & (keycache->key_cache_block_size-1));
+ offset= (uint) (filepos % keycache->key_cache_block_size);
do
{
keycache_pthread_mutex_lock(&keycache->cache_lock);
@@ -2081,7 +2080,7 @@ int key_cache_write(KEY_CACHE *keycache,
int page_st;
uint offset;
- offset= (uint) (filepos & (keycache->key_cache_block_size-1));
+ offset= (uint) (filepos % keycache->key_cache_block_size);
do
{
keycache_pthread_mutex_lock(&keycache->cache_lock);
diff --git a/mysys/my_conio.c b/mysys/my_conio.c
index 23b0c55e7a9..def15674f26 100644
--- a/mysys/my_conio.c
+++ b/mysys/my_conio.c
@@ -184,16 +184,19 @@ char* my_cgets(char *buffer, unsigned long clen, unsigned long* plen)
}
while (GetLastError() == ERROR_NOT_ENOUGH_MEMORY);
+ /* We go here on error reading the string (Ctrl-C for example) */
+ if (!*plen)
+ result= NULL; /* purecov: inspected */
if (result != NULL)
{
- if (buffer[*plen - 2] == '\r')
+ if (*plen > 1 && buffer[*plen - 2] == '\r')
{
*plen= *plen - 2;
}
else
{
- if (buffer[*plen - 1] == '\r')
+ if (*plen > 0 && buffer[*plen - 1] == '\r')
{
char tmp[3];
int tmplen= sizeof(tmp);
diff --git a/mysys/my_init.c b/mysys/my_init.c
index 2bcf5f44c4d..32d3f07fd31 100644
--- a/mysys/my_init.c
+++ b/mysys/my_init.c
@@ -262,6 +262,34 @@ void my_parameter_handler(const wchar_t * expression, const wchar_t * function,
}
+#ifdef __MSVC_RUNTIME_CHECKS
+#include <rtcapi.h>
+
+/* Turn off runtime checks for 'handle_rtc_failure' */
+#pragma runtime_checks("", off)
+
+/*
+ handle_rtc_failure
+ Catch the RTC error and dump it to stderr
+*/
+
+int handle_rtc_failure(int err_type, const char *file, int line,
+ const char* module, const char *format, ...)
+{
+ va_list args;
+ va_start(args, format);
+ fprintf(stderr, "Error:");
+ vfprintf(stderr, format, args);
+ fprintf(stderr, " At %s:%d\n", file, line);
+ va_end(args);
+ (void) fflush(stderr);
+
+ return 0; /* Error is handled */
+}
+#pragma runtime_checks("", on)
+#endif
+
+
static void my_win_init(void)
{
HKEY hSoftMysql ;
@@ -292,6 +320,14 @@ static void my_win_init(void)
_set_invalid_parameter_handler(my_parameter_handler);
#endif
#endif
+#ifdef __MSVC_RUNTIME_CHECKS
+ /*
+ Install handler to send RTC (Runtime Error Check) warnings
+ to log file
+ */
+ _RTC_SetErrorFunc(handle_rtc_failure);
+#endif
+
_tzset();
/* apre la chiave HKEY_LOCAL_MACHINES\software\MySQL */
diff --git a/mysys/my_seek.c b/mysys/my_seek.c
index 3d415400aa2..5c1a6c44b6f 100644
--- a/mysys/my_seek.c
+++ b/mysys/my_seek.c
@@ -88,6 +88,7 @@ my_off_t my_tell(File fd, myf MyFlags __attribute__((unused)))
os_off_t pos;
DBUG_ENTER("my_tell");
DBUG_PRINT("my",("Fd: %d MyFlags: %d",fd, MyFlags));
+ DBUG_ASSERT(fd >= 0);
#ifdef HAVE_TELL
pos=tell(fd);
#else
diff --git a/mysys/my_symlink2.c b/mysys/my_symlink2.c
index 2ad08ef67de..e2493874097 100644
--- a/mysys/my_symlink2.c
+++ b/mysys/my_symlink2.c
@@ -52,11 +52,13 @@ File my_create_with_symlink(const char *linkname, const char *filename,
{
if (!access(filename,F_OK))
{
+ my_errno= errno= EEXIST;
my_error(EE_CANTCREATEFILE, MYF(0), filename, EEXIST);
DBUG_RETURN(-1);
}
if (create_link && !access(linkname,F_OK))
{
+ my_errno= errno= EEXIST;
my_error(EE_CANTCREATEFILE, MYF(0), linkname, EEXIST);
DBUG_RETURN(-1);
}
diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c
index 07a92e34dd3..cf7ea0a800f 100644
--- a/mysys/my_thr_init.c
+++ b/mysys/my_thr_init.c
@@ -87,27 +87,31 @@ my_bool my_thread_global_init(void)
fprintf(stderr,"Can't initialize threads: error %d\n", pth_ret);
return 1;
}
-
-#ifdef NPTL_PTHREAD_EXIT_BUG
-
-/*
- BUG#24507: Race conditions inside current NPTL pthread_exit() implementation.
- To avoid a possible segmentation fault during concurrent executions of
- pthread_exit(), a dummy thread is spawned which initializes internal variables
- of pthread lib. See bug description for thoroughfull explanation.
-
- TODO: Remove this code when fixed versions of glibc6 are in common use.
-*/
+#ifdef NPTL_PTHREAD_EXIT_BUG
+ /*
+ BUG#24507: Race conditions inside current NPTL pthread_exit()
+ implementation.
- pthread_t dummy_thread;
- pthread_attr_t dummy_thread_attr;
+ To avoid a possible segmentation fault during concurrent
+ executions of pthread_exit(), a dummy thread is spawned which
+ initializes internal variables of pthread lib. See bug description
+ for a full explanation.
- pthread_attr_init(&dummy_thread_attr);
- pthread_attr_setdetachstate(&dummy_thread_attr,PTHREAD_CREATE_DETACHED);
+ TODO: Remove this code when fixed versions of glibc6 are in common
+ use.
+ */
+ if (thd_lib_detected == THD_LIB_NPTL)
+ {
+ pthread_t dummy_thread;
+ pthread_attr_t dummy_thread_attr;
- pthread_create(&dummy_thread,&dummy_thread_attr,nptl_pthread_exit_hack_handler,NULL);
+ pthread_attr_init(&dummy_thread_attr);
+ pthread_attr_setdetachstate(&dummy_thread_attr, PTHREAD_CREATE_DETACHED);
+ pthread_create(&dummy_thread,&dummy_thread_attr,
+ nptl_pthread_exit_hack_handler, NULL);
+ }
#endif
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP