MCPcopy Create free account
hub / github.com/MariaDB/server / c_ptr

Method c_ptr

sql/sql_string.h:665–694  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

663 }
664
665 inline char *c_ptr()
666 {
667 if (unlikely(!Ptr))
668 return (char*) "";
669 /*
670 Here we assume that any buffer used to initialize String has
671 an end \0 or have at least an accessable character at end.
672 This is to handle the case of String("Hello",5) and
673 String("hello",5) efficiently.
674
675 We have two options here. To test for !Alloced_length or !alloced.
676 Using "Alloced_length" is slightly safer so that we do not read
677 from potentially uninitialized memory (normally not dangerous but
678 may give warnings in valgrind), but "alloced" is safer as there
679 are less change to get memory loss from code that is using
680 String((char*), length) or String.set((char*), length) and does
681 not free things properly (and there is several places in the code
682 where this happens and it is hard to find out if any of these will call
683 c_ptr().
684 */
685 if (unlikely(!alloced && !Ptr[str_length]))
686 return Ptr;
687 if (str_length < Alloced_length)
688 {
689 Ptr[str_length]=0;
690 return Ptr;
691 }
692 (void) realloc(str_length); /* This will add end \0 */
693 return Ptr;
694 }
695 /*
696 One should use c_ptr() instead for most cases. This will be deleted soon,
697 kept for compatibility.

Callers 15

print_explainMethod · 0.45
mark_as_eliminatedFunction · 0.45
dbug_print_depsMethod · 0.45
store_server_fieldsFunction · 0.45
mysql_insertFunction · 0.45
send_eofMethod · 0.45
fix_length_and_decMethod · 0.45
val_strMethod · 0.45
get_formatMethod · 0.45
parse_nls_paramMethod · 0.45
get_dateMethod · 0.45
choose_best_splittingMethod · 0.45

Calls

no outgoing calls

Tested by 3

TEST_joinFunction · 0.36
print_keyuseFunction · 0.36
print_sjmFunction · 0.36