summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2020-08-13 20:17:00 +0300
committerMonty <monty@mariadb.org>2021-01-19 20:17:45 +0200
commit503dde2e8e7c2d7668db7f38cdce7393f795929b (patch)
treeeb6790be8a8561b2d2fb96dcb6b1424a70d8c9c9
parent1b86a41391dd01a3df830f4292b742f206474e05 (diff)
downloadmariadb-git-503dde2e8e7c2d7668db7f38cdce7393f795929b.tar.gz
Add support for minimum field width for strings to my_vsnprintf()
-rw-r--r--mysql-test/main/almost_full.result8
-rw-r--r--mysql-test/main/grant4.result8
-rw-r--r--mysql-test/main/myisam.result8
-rw-r--r--mysql-test/main/myisam_crash_before_flush_keys.result2
-rw-r--r--mysql-test/main/myisam_recover.result12
-rw-r--r--mysql-test/main/mysqlcheck.result4
-rw-r--r--mysql-test/suite/maria/maria-recovery3.result2
-rw-r--r--mysql-test/suite/maria/max_length.result10
-rw-r--r--mysql-test/suite/parts/r/partition_recover_myisam.result8
-rw-r--r--mysql-test/suite/parts/r/partition_repair_myisam.result48
-rw-r--r--strings/my_vsnprintf.c52
-rw-r--r--unittest/mysys/my_vsnprintf-t.c9
12 files changed, 101 insertions, 70 deletions
diff --git a/mysql-test/main/almost_full.result b/mysql-test/main/almost_full.result
index b2d7092aa51..4b5c8417412 100644
--- a/mysql-test/main/almost_full.result
+++ b/mysql-test/main/almost_full.result
@@ -7,24 +7,24 @@ INSERT INTO t1 SET b=repeat('a',600);
ERROR HY000: The table 't1' is full
CHECK TABLE t1 EXTENDED;
Table Op Msg_type Msg_text
-test.t1 check warning Datafile is almost full, 65448 of 65534 used
+test.t1 check warning Datafile is almost full, 65448 of 65534 used
test.t1 check status OK
UPDATE t1 SET b=repeat('a', 800) where a=10;
ERROR HY000: The table 't1' is full
CHECK TABLE t1 EXTENDED;
Table Op Msg_type Msg_text
-test.t1 check warning Datafile is almost full, 65448 of 65534 used
+test.t1 check warning Datafile is almost full, 65448 of 65534 used
test.t1 check status OK
INSERT INTO t1 SET b=repeat('a',400);
CHECK TABLE t1 EXTENDED;
Table Op Msg_type Msg_text
-test.t1 check warning Datafile is almost full, 65448 of 65534 used
+test.t1 check warning Datafile is almost full, 65448 of 65534 used
test.t1 check status OK
DELETE FROM t1 WHERE a=2 or a=6;
UPDATE t1 SET b=repeat('a', 600) where a=11;
CHECK TABLE t1 EXTENDED;
Table Op Msg_type Msg_text
-test.t1 check warning Datafile is almost full, 65448 of 65534 used
+test.t1 check warning Datafile is almost full, 65448 of 65534 used
test.t1 check status OK
drop table t1;
set global myisam_data_pointer_size=default;
diff --git a/mysql-test/main/grant4.result b/mysql-test/main/grant4.result
index 29021b608aa..9c46a2d9e98 100644
--- a/mysql-test/main/grant4.result
+++ b/mysql-test/main/grant4.result
@@ -187,8 +187,8 @@ connection con1;
check table mysqltest_db1.t1;
Table Op Msg_type Msg_text
mysqltest_db1.t1 check warning 1 client is using or hasn't closed the table properly
-mysqltest_db1.t1 check error Size of indexfile is: 1024 Should be: 2048
-mysqltest_db1.t1 check warning Size of datafile is: 14 Should be: 7
+mysqltest_db1.t1 check error Size of indexfile is: 1024 Should be: 2048
+mysqltest_db1.t1 check warning Size of datafile is: 14 Should be: 7
mysqltest_db1.t1 check error Corrupt
# The below statement should fail before repairing t1.
# Otherwise info about such repair will be missing from its result-set.
@@ -201,8 +201,8 @@ check table mysqltest_db1.t1;
Table Op Msg_type Msg_text
mysqltest_db1.t1 check warning Table is marked as crashed
mysqltest_db1.t1 check warning 1 client is using or hasn't closed the table properly
-mysqltest_db1.t1 check error Size of indexfile is: 1024 Should be: 2048
-mysqltest_db1.t1 check warning Size of datafile is: 14 Should be: 7
+mysqltest_db1.t1 check error Size of indexfile is: 1024 Should be: 2048
+mysqltest_db1.t1 check warning Size of datafile is: 14 Should be: 7
mysqltest_db1.t1 check error Corrupt
repair table mysqltest_db1.t1;
Table Op Msg_type Msg_text
diff --git a/mysql-test/main/myisam.result b/mysql-test/main/myisam.result
index 1178cca9ed0..269541902ed 100644
--- a/mysql-test/main/myisam.result
+++ b/mysql-test/main/myisam.result
@@ -2643,8 +2643,8 @@ FLUSH TABLES;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check warning 1 client is using or hasn't closed the table properly
-test.t1 check error Size of indexfile is: 1024 Should be: 2048
-test.t1 check warning Size of datafile is: 14 Should be: 7
+test.t1 check error Size of indexfile is: 1024 Should be: 2048
+test.t1 check warning Size of datafile is: 14 Should be: 7
test.t1 check error Corrupt
# Alter table should report error and not auto-repair the table.
ALTER TABLE t1 ENGINE = MyISAM;
@@ -2653,8 +2653,8 @@ CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check warning Table is marked as crashed
test.t1 check warning 1 client is using or hasn't closed the table properly
-test.t1 check error Size of indexfile is: 1024 Should be: 2048
-test.t1 check warning Size of datafile is: 14 Should be: 7
+test.t1 check error Size of indexfile is: 1024 Should be: 2048
+test.t1 check warning Size of datafile is: 14 Should be: 7
test.t1 check error Corrupt
DROP TABLE t1;
#
diff --git a/mysql-test/main/myisam_crash_before_flush_keys.result b/mysql-test/main/myisam_crash_before_flush_keys.result
index 7d929ffb644..c839d195a9c 100644
--- a/mysql-test/main/myisam_crash_before_flush_keys.result
+++ b/mysql-test/main/myisam_crash_before_flush_keys.result
@@ -25,6 +25,6 @@ ERROR HY000: Lost connection to MySQL server during query
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check warning 1 client is using or hasn't closed the table properly
-test.t1 check error Size of indexfile is: 1024 Should be: 3072
+test.t1 check error Size of indexfile is: 1024 Should be: 3072
test.t1 check error Corrupt
DROP TABLE t1;
diff --git a/mysql-test/main/myisam_recover.result b/mysql-test/main/myisam_recover.result
index da96682186c..d3c385bc49b 100644
--- a/mysql-test/main/myisam_recover.result
+++ b/mysql-test/main/myisam_recover.result
@@ -69,9 +69,9 @@ flush table t1;
# check table is needed to mark the table as crashed.
check table t1;
Table Op Msg_type Msg_text
-test.t1 check warning Size of datafile is: 42 Should be: 21
-test.t1 check error Record-count is not ok; is 6 Should be: 3
-test.t1 check warning Found 6 key parts. Should be: 3
+test.t1 check warning Size of datafile is: 42 Should be: 21
+test.t1 check error Record-count is not ok; is 6 Should be: 3
+test.t1 check warning Found 6 key parts. Should be: 3
test.t1 check error Corrupt
#
# At this point we have a merge table t1_mrg pointing to t1,
@@ -122,9 +122,9 @@ flush table t1;
# Check table is needed to mark the table as crashed.
check table t1;
Table Op Msg_type Msg_text
-test.t1 check warning Size of datafile is: 14 Should be: 7
-test.t1 check error Record-count is not ok; is 2 Should be: 1
-test.t1 check warning Found 2 key parts. Should be: 1
+test.t1 check warning Size of datafile is: 14 Should be: 7
+test.t1 check error Record-count is not ok; is 2 Should be: 1
+test.t1 check warning Found 2 key parts. Should be: 1
test.t1 check error Corrupt
# At this point we have a corrupt t1
set autocommit = 0;
diff --git a/mysql-test/main/mysqlcheck.result b/mysql-test/main/mysqlcheck.result
index 8b6a19b5270..bace4f0ef3a 100644
--- a/mysql-test/main/mysqlcheck.result
+++ b/mysql-test/main/mysqlcheck.result
@@ -427,7 +427,7 @@ create table mysqltest1.t1 (a int) engine=myisam;
create table t2 (a int);
check table mysqltest1.t1;
Table Op Msg_type Msg_text
-mysqltest1.t1 check warning Size of datafile is: 4 Should be: 0
+mysqltest1.t1 check warning Size of datafile is: 4 Should be: 0
mysqltest1.t1 check error got error: 0 when reading datafile at record: 0
mysqltest1.t1 check error Corrupt
mtr.global_suppressions Table is already up to date
@@ -462,7 +462,7 @@ mysql.time_zone_transition_type Table is already up to date
mysql.transaction_registry OK
mysqltest1.t1
warning : Table is marked as crashed
-warning : Size of datafile is: 4 Should be: 0
+warning : Size of datafile is: 4 Should be: 0
error : got error: 0 when reading datafile at record: 0
error : Corrupt
test.t2 Table is already up to date
diff --git a/mysql-test/suite/maria/maria-recovery3.result b/mysql-test/suite/maria/maria-recovery3.result
index 9d25cd13b90..d7e98e54cd1 100644
--- a/mysql-test/suite/maria/maria-recovery3.result
+++ b/mysql-test/suite/maria/maria-recovery3.result
@@ -100,7 +100,7 @@ ERROR HY000: Lost connection to MySQL server during query
* recovery happens
check table t1 extended;
Table Op Msg_type Msg_text
-mysqltest.t1 check warning Size of indexfile is: <SIZE> Expected: 8192
+mysqltest.t1 check warning Size of indexfile is: <SIZE> Expected: 8192
mysqltest.t1 check status OK
* testing that checksum after recovery is as expected
Checksum-check
diff --git a/mysql-test/suite/maria/max_length.result b/mysql-test/suite/maria/max_length.result
index 4403ce5d0d2..ca02eb6f4b2 100644
--- a/mysql-test/suite/maria/max_length.result
+++ b/mysql-test/suite/maria/max_length.result
@@ -54,20 +54,20 @@ insert into t1 (v,b) select v,b from t2;
ERROR HY000: The table 't1' is full
check table t1;
Table Op Msg_type Msg_text
-test.t1 check warning Datafile is almost full, 268230656 of 268320768 used
+test.t1 check warning Datafile is almost full, 268230656 of 268320768 used
test.t1 check status OK
insert into t1 values(null, repeat("gh",400),repeat("jkl",10000));
ERROR HY000: The table 't1' is full
check table t1;
Table Op Msg_type Msg_text
-test.t1 check warning Datafile is almost full, 268230656 of 268320768 used
+test.t1 check warning Datafile is almost full, 268230656 of 268320768 used
test.t1 check status OK
truncate table t1;
insert into t1 (v,b) select v,b from t2;
ERROR HY000: The table 't1' is full
check table t1;
Table Op Msg_type Msg_text
-test.t1 check warning Datafile is almost full, 268230656 of 268320768 used
+test.t1 check warning Datafile is almost full, 268230656 of 268320768 used
test.t1 check status OK
drop table t1,t2;
create table t1 (
@@ -135,7 +135,7 @@ count(*)
3276
check table t1;
Table Op Msg_type Msg_text
-test.t1 check warning Datafile is almost full, 65520 of 65535 used
+test.t1 check warning Datafile is almost full, 65520 of 65535 used
test.t1 check status OK
create or replace table t1 (
c1 int unsigned,
@@ -172,7 +172,7 @@ count(*)
6189940
check table t1;
Table Op Msg_type Msg_text
-test.t1 check warning Datafile is almost full, 268320768 of 268320768 used
+test.t1 check warning Datafile is almost full, 268320768 of 268320768 used
test.t1 check status OK
show table status like "t1";
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Max_index_length Temporary
diff --git a/mysql-test/suite/parts/r/partition_recover_myisam.result b/mysql-test/suite/parts/r/partition_recover_myisam.result
index 151ff802a82..1eddf51b087 100644
--- a/mysql-test/suite/parts/r/partition_recover_myisam.result
+++ b/mysql-test/suite/parts/r/partition_recover_myisam.result
@@ -19,8 +19,8 @@ a
Warnings:
Error 145 Table 't1_will_crash' is marked as crashed and should be repaired
Warning 1034 1 client is using or hasn't closed the table properly
-Error 1034 Size of indexfile is: 1024 Should be: 2048
-Warning 1034 Size of datafile is: 77 Should be: 7
+Error 1034 Size of indexfile is: 1024 Should be: 2048
+Warning 1034 Size of datafile is: 77 Should be: 7
Warning 1034 Number of rows changed from 1 to 11
DROP TABLE t1_will_crash;
CREATE TABLE t1_will_crash (a INT, KEY (a))
@@ -48,7 +48,7 @@ a
Warnings:
Error 145 Table 't1_will_crash#P#p1' is marked as crashed and should be repaired
Warning 1034 1 client is using or hasn't closed the table properly
-Error 1034 Size of indexfile is: 1024 Should be: 2048
-Warning 1034 Size of datafile is: 28 Should be: 7
+Error 1034 Size of indexfile is: 1024 Should be: 2048
+Warning 1034 Size of datafile is: 28 Should be: 7
Warning 1034 Number of rows changed from 1 to 4
DROP TABLE t1_will_crash;
diff --git a/mysql-test/suite/parts/r/partition_repair_myisam.result b/mysql-test/suite/parts/r/partition_repair_myisam.result
index 0521263df12..f534adf9244 100644
--- a/mysql-test/suite/parts/r/partition_repair_myisam.result
+++ b/mysql-test/suite/parts/r/partition_repair_myisam.result
@@ -16,8 +16,8 @@ FLUSH TABLES;
CHECK TABLE tp;
Table Op Msg_type Msg_text
test.tp check warning 1 client is using or hasn't closed the table properly
-test.tp check error Size of indexfile is: 1024 Should be: 2048
-test.tp check warning Size of datafile is: 77 Should be: 7
+test.tp check error Size of indexfile is: 1024 Should be: 2048
+test.tp check warning Size of datafile is: 77 Should be: 7
test.tp check error Partition pCrashed returned error
test.tp check error Corrupt
ALTER TABLE tp EXCHANGE PARTITION pCrashed WITH TABLE t;
@@ -40,8 +40,8 @@ FLUSH TABLES;
CHECK TABLE t;
Table Op Msg_type Msg_text
test.t check warning 1 client is using or hasn't closed the table properly
-test.t check error Size of indexfile is: 1024 Should be: 2048
-test.t check warning Size of datafile is: 77 Should be: 7
+test.t check error Size of indexfile is: 1024 Should be: 2048
+test.t check warning Size of datafile is: 77 Should be: 7
test.t check error Corrupt
ALTER TABLE tp EXCHANGE PARTITION pCrashed WITH TABLE t;
ERROR HY000: Table './test/t' is marked as crashed and should be repaired
@@ -69,8 +69,8 @@ FLUSH TABLES;
CHECK TABLE t1_will_crash;
Table Op Msg_type Msg_text
test.t1_will_crash check warning 1 client is using or hasn't closed the table properly
-test.t1_will_crash check error Size of indexfile is: 1024 Should be: 2048
-test.t1_will_crash check warning Size of datafile is: 77 Should be: 7
+test.t1_will_crash check error Size of indexfile is: 1024 Should be: 2048
+test.t1_will_crash check warning Size of datafile is: 77 Should be: 7
test.t1_will_crash check error Corrupt
REPAIR TABLE t1_will_crash;
Table Op Msg_type Msg_text
@@ -104,8 +104,8 @@ FLUSH TABLES;
CHECK TABLE t1_will_crash;
Table Op Msg_type Msg_text
test.t1_will_crash check warning 1 client is using or hasn't closed the table properly
-test.t1_will_crash check error Size of indexfile is: 1024 Should be: 2048
-test.t1_will_crash check warning Size of datafile is: 28 Should be: 7
+test.t1_will_crash check error Size of indexfile is: 1024 Should be: 2048
+test.t1_will_crash check warning Size of datafile is: 28 Should be: 7
test.t1_will_crash check error Partition p1 returned error
test.t1_will_crash check error Corrupt
REPAIR TABLE t1_will_crash;
@@ -134,16 +134,16 @@ test.t1_will_crash check status OK
ALTER TABLE t1_will_crash CHECK PARTITION p0, p1;
Table Op Msg_type Msg_text
test.t1_will_crash check warning 1 client is using or hasn't closed the table properly
-test.t1_will_crash check error Size of indexfile is: 1024 Should be: 2048
-test.t1_will_crash check warning Size of datafile is: 28 Should be: 7
+test.t1_will_crash check error Size of indexfile is: 1024 Should be: 2048
+test.t1_will_crash check warning Size of datafile is: 28 Should be: 7
test.t1_will_crash check error Partition p1 returned error
test.t1_will_crash check error Corrupt
ALTER TABLE t1_will_crash CHECK PARTITION p1, p2;
Table Op Msg_type Msg_text
test.t1_will_crash check warning Table is marked as crashed
test.t1_will_crash check warning 1 client is using or hasn't closed the table properly
-test.t1_will_crash check error Size of indexfile is: 1024 Should be: 2048
-test.t1_will_crash check warning Size of datafile is: 28 Should be: 7
+test.t1_will_crash check error Size of indexfile is: 1024 Should be: 2048
+test.t1_will_crash check warning Size of datafile is: 28 Should be: 7
test.t1_will_crash check error Partition p1 returned error
test.t1_will_crash check error Corrupt
ALTER TABLE t1_will_crash REPAIR PARTITION p0, p2;
@@ -195,8 +195,8 @@ FLUSH TABLES;
CHECK TABLE t1_will_crash;
Table Op Msg_type Msg_text
test.t1_will_crash check warning 1 client is using or hasn't closed the table properly
-test.t1_will_crash check error Size of indexfile is: 1024 Should be: 2048
-test.t1_will_crash check warning Size of datafile is: 14 Should be: 7
+test.t1_will_crash check error Size of indexfile is: 1024 Should be: 2048
+test.t1_will_crash check warning Size of datafile is: 14 Should be: 7
test.t1_will_crash check error Subpartition p1sp0 returned error
test.t1_will_crash check error Corrupt
REPAIR TABLE t1_will_crash;
@@ -225,16 +225,16 @@ test.t1_will_crash check status OK
ALTER TABLE t1_will_crash CHECK PARTITION all;
Table Op Msg_type Msg_text
test.t1_will_crash check warning 1 client is using or hasn't closed the table properly
-test.t1_will_crash check error Size of indexfile is: 1024 Should be: 2048
-test.t1_will_crash check warning Size of datafile is: 14 Should be: 7
+test.t1_will_crash check error Size of indexfile is: 1024 Should be: 2048
+test.t1_will_crash check warning Size of datafile is: 14 Should be: 7
test.t1_will_crash check error Subpartition p1sp0 returned error
test.t1_will_crash check error Corrupt
ALTER TABLE t1_will_crash CHECK PARTITION p1;
Table Op Msg_type Msg_text
test.t1_will_crash check warning Table is marked as crashed
test.t1_will_crash check warning 1 client is using or hasn't closed the table properly
-test.t1_will_crash check error Size of indexfile is: 1024 Should be: 2048
-test.t1_will_crash check warning Size of datafile is: 14 Should be: 7
+test.t1_will_crash check error Size of indexfile is: 1024 Should be: 2048
+test.t1_will_crash check warning Size of datafile is: 14 Should be: 7
test.t1_will_crash check error Subpartition p1sp0 returned error
test.t1_will_crash check error Corrupt
ALTER TABLE t1_will_crash REPAIR PARTITION p0;
@@ -331,7 +331,7 @@ test.t1_will_crash optimize warning Number of rows changed from 8 to 7
test.t1_will_crash optimize status OK
CHECK TABLE t1_will_crash;
Table Op Msg_type Msg_text
-test.t1_will_crash check error Size of datafile is: 0 Should be: 164
+test.t1_will_crash check error Size of datafile is: 0 Should be: 164
test.t1_will_crash check error Partition p0 returned error
test.t1_will_crash check error Corrupt
REPAIR TABLE t1_will_crash;
@@ -406,7 +406,7 @@ ALTER TABLE t1_will_crash CHECK PARTITION p4;
Table Op Msg_type Msg_text
test.t1_will_crash check warning Table is marked as crashed and last repair failed
test.t1_will_crash check warning 1 client is using or hasn't closed the table properly
-test.t1_will_crash check warning Size of datafile is: 368 Should be: 252
+test.t1_will_crash check warning Size of datafile is: 368 Should be: 252
test.t1_will_crash check error Found 4 keys of 3
test.t1_will_crash check error Partition p4 returned error
test.t1_will_crash check error Corrupt
@@ -419,7 +419,7 @@ FLUSH TABLES;
# replacing p6 with a crashed MYD file (2) (splitted dynamic record)
ALTER TABLE t1_will_crash CHECK PARTITION p6;
Table Op Msg_type Msg_text
-test.t1_will_crash check warning Size of datafile is: 868 Should be: 604
+test.t1_will_crash check warning Size of datafile is: 868 Should be: 604
test.t1_will_crash check error Unexpected byte: 0 at link: 340
test.t1_will_crash check error Partition p6 returned error
test.t1_will_crash check error Corrupt
@@ -472,9 +472,9 @@ partition b a
SET @@optimizer_switch=@save_optimizer_switch;
ALTER TABLE t1_will_crash CHECK PARTITION p6;
Table Op Msg_type Msg_text
-test.t1_will_crash check warning Size of datafile is: 868 Should be: 604
-test.t1_will_crash check error Record-count is not ok; is 8 Should be: 7
-test.t1_will_crash check warning Found 10 key parts. Should be: 7
+test.t1_will_crash check warning Size of datafile is: 868 Should be: 604
+test.t1_will_crash check error Record-count is not ok; is 8 Should be: 7
+test.t1_will_crash check warning Found 10 key parts. Should be: 7
test.t1_will_crash check error Partition p6 returned error
test.t1_will_crash check error Corrupt
ALTER TABLE t1_will_crash REPAIR PARTITION p6;
diff --git a/strings/my_vsnprintf.c b/strings/my_vsnprintf.c
index a2e3f9b738d..1621db2e412 100644
--- a/strings/my_vsnprintf.c
+++ b/strings/my_vsnprintf.c
@@ -224,12 +224,27 @@ err:
*/
static char *process_str_arg(CHARSET_INFO *cs, char *to, const char *end,
- size_t width, char *par, uint print_type,
- my_bool nice_cut)
+ longlong length_arg, size_t width, char *par,
+ uint print_type, my_bool nice_cut)
{
int well_formed_error;
uint dots= 0;
size_t plen, left_len= (size_t) (end - to) + 1, slen=0;
+ my_bool left_fill= 1;
+ size_t length;
+
+ /*
+ The sign of the length argument specific the string should be right
+ or left adjusted
+ */
+ if (length_arg < 0)
+ {
+ length= -length_arg;
+ left_fill= 0;
+ }
+ else
+ length= (size_t) length_arg;
+
if (!par)
par = (char*) "(null)";
@@ -265,18 +280,25 @@ static char *process_str_arg(CHARSET_INFO *cs, char *to, const char *end,
plen= my_well_formed_length(cs, par, par + plen, width, &well_formed_error);
if (print_type & ESCAPED_ARG)
{
+ const char *org_to= to;
to= backtick_string(cs, to, end, par, plen + dots, '`', MY_TEST(dots));
+ plen= (size_t) (to - org_to);
dots= 0;
}
else
- to= strnmov(to,par,plen);
-
- if (dots)
{
- for (; dots; dots--)
- *(to++)= '.';
- *(to)= 0;
+ if (left_fill)
+ {
+ if (plen + dots < length)
+ to= strfill(to, length - plen - dots, ' ');
+ }
+ to= strnmov(to,par,plen);
+ if (dots)
+ to= strfill(to, dots, '.');
}
+
+ if (!left_fill && plen + dots < length)
+ to= strfill(to, length - plen - dots, ' ');
return to;
}
@@ -494,11 +516,16 @@ start:
case 's':
case 'T':
{
+ longlong min_field_width;
char *par= args_arr[print_arr[i].arg_idx].str_arg;
width= (print_arr[i].flags & WIDTH_ARG)
? (size_t)args_arr[print_arr[i].width].longlong_arg
: print_arr[i].width;
- to= process_str_arg(cs, to, end, width, par, print_arr[i].flags,
+ min_field_width= (print_arr[i].flags & LENGTH_ARG)
+ ? args_arr[print_arr[i].length].longlong_arg
+ : (longlong) print_arr[i].length;
+ to= process_str_arg(cs, to, end, min_field_width, width, par,
+ print_arr[i].flags,
(print_arr[i].arg_type == 'T'));
break;
}
@@ -565,7 +592,7 @@ start:
*to++= ' ';
*to++= '"';
my_strerror(errmsg_buff, sizeof(errmsg_buff), (int) larg);
- to= process_str_arg(cs, to, real_end, width, errmsg_buff,
+ to= process_str_arg(cs, to, real_end, 0, width, errmsg_buff,
print_arr[i].flags, 1);
if (real_end > to) *to++= '"';
}
@@ -693,7 +720,8 @@ size_t my_vsnprintf_ex(CHARSET_INFO *cs, char *to, size_t n,
if (*fmt == 's' || *fmt == 'T') /* String parameter */
{
reg2 char *par= va_arg(ap, char *);
- to= process_str_arg(cs, to, end, width, par, print_type, (*fmt == 'T'));
+ to= process_str_arg(cs, to, end, (longlong) length, width, par,
+ print_type, (*fmt == 'T'));
continue;
}
else if (*fmt == 'b') /* Buffer parameter */
@@ -751,7 +779,7 @@ size_t my_vsnprintf_ex(CHARSET_INFO *cs, char *to, size_t n,
*to++= ' ';
*to++= '"';
my_strerror(errmsg_buff, sizeof(errmsg_buff), (int) larg);
- to= process_str_arg(cs, to, real_end, width, errmsg_buff,
+ to= process_str_arg(cs, to, real_end, 0, width, errmsg_buff,
print_type, 1);
if (real_end > to) *to++= '"';
}
diff --git a/unittest/mysys/my_vsnprintf-t.c b/unittest/mysys/my_vsnprintf-t.c
index 1a0b4080a2d..af17f6e3854 100644
--- a/unittest/mysys/my_vsnprintf-t.c
+++ b/unittest/mysys/my_vsnprintf-t.c
@@ -61,7 +61,7 @@ static void test_many(const char **res, const char *fmt, ...)
int main(void)
{
- plan(47);
+ plan(48);
test1("Constant string",
"Constant string");
@@ -96,8 +96,11 @@ int main(void)
test1("Flag '0' works <0006>",
"Flag '0' works <%04d>", 6);
- test1("Width is ignored for strings <x> <y>",
- "Width is ignored for strings <%04s> <%5s>", "x", "y");
+ test1("Width for strings < x> < y>",
+ "Width for strings <%04s> <%5s>", "x", "y");
+
+ test1("Negative width is ignored for strings < x> < y>",
+ "Negative width is ignored for strings <%-4s> <%-5s>", "x", "y");
test1("Precision works for strings <abcde>",
"Precision works for strings <%.5s>", "abcdef!");