mirror of
https://github.com/xroche/httrack.git
synced 2026-07-18 14:50:32 +03:00
Compare commits
1 Commits
drop-swf-j
...
string-mac
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02796dff34 |
@@ -524,6 +524,41 @@ static int string_safety_selftests(void) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* StringCatN/StringSetLength must eval SIZE once: (n_eval++, V) leaves
|
||||||
|
n_eval == 2 on a double-eval macro. */
|
||||||
|
{
|
||||||
|
String s = STRING_EMPTY;
|
||||||
|
int n_eval = 0;
|
||||||
|
|
||||||
|
StringCat(s, "hello");
|
||||||
|
StringCatN(s, "world", (n_eval++, 3)); /* strlen>SIZE so the clamp runs */
|
||||||
|
if (n_eval != 1 || strcmp(StringBuff(s), "hellowor") != 0) {
|
||||||
|
StringFree(s);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
n_eval = 0;
|
||||||
|
StringSetLength(s, (n_eval++, 5));
|
||||||
|
if (n_eval != 1 || StringLength(s) != 5) {
|
||||||
|
StringFree(s);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
StringFree(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* StringSubRW still reads/writes after dropping its duplicate definition. */
|
||||||
|
{
|
||||||
|
String s = STRING_EMPTY;
|
||||||
|
|
||||||
|
StringCat(s, "abc");
|
||||||
|
StringSubRW(s, 1) = 'X';
|
||||||
|
if (StringSub(s, 1) != 'X' || strcmp(StringBuff(s), "aXc") != 0) {
|
||||||
|
StringFree(s);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
StringFree(s);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,9 +121,6 @@ struct String {
|
|||||||
/** Byte at POS (read/write). No bounds check; POS must be < StringLength. **/
|
/** Byte at POS (read/write). No bounds check; POS must be < StringLength. **/
|
||||||
#define StringSubRW(BLK, POS) (StringBuffRW(BLK)[POS])
|
#define StringSubRW(BLK, POS) (StringBuffRW(BLK)[POS])
|
||||||
|
|
||||||
/** Subcharacter (read/write) **/
|
|
||||||
#define StringSubRW(BLK, POS) (StringBuffRW(BLK)[POS])
|
|
||||||
|
|
||||||
/** Byte POS positions from the end (read). POS==1 is the last byte. **/
|
/** Byte POS positions from the end (read). POS==1 is the last byte. **/
|
||||||
#define StringRight(BLK, POS) (StringBuff(BLK)[StringLength(BLK) - POS])
|
#define StringRight(BLK, POS) (StringBuff(BLK)[StringLength(BLK) - POS])
|
||||||
|
|
||||||
@@ -191,8 +188,9 @@ HTS_STATIC char *StringBuffN_(String *blk, int size) {
|
|||||||
asserts SIZE fits the existing content; does not (re)allocate. **/
|
asserts SIZE fits the existing content; does not (re)allocate. **/
|
||||||
#define StringSetLength(BLK, SIZE) \
|
#define StringSetLength(BLK, SIZE) \
|
||||||
do { \
|
do { \
|
||||||
if (SIZE >= 0) { \
|
const int len__ = (SIZE); /* signed: negative means strlen(buffer_) */ \
|
||||||
(BLK).length_ = SIZE; \
|
if (len__ >= 0) { \
|
||||||
|
(BLK).length_ = len__; \
|
||||||
} else { \
|
} else { \
|
||||||
(BLK).length_ = strlen((BLK).buffer_); \
|
(BLK).length_ = strlen((BLK).buffer_); \
|
||||||
} \
|
} \
|
||||||
@@ -308,10 +306,11 @@ HTS_STATIC void StringAttach(String *blk, char **str) {
|
|||||||
#define StringCatN(BLK, STR, SIZE) \
|
#define StringCatN(BLK, STR, SIZE) \
|
||||||
do { \
|
do { \
|
||||||
const char *str__ = (STR); \
|
const char *str__ = (STR); \
|
||||||
|
const size_t usize__ = (SIZE); \
|
||||||
if (str__ != NULL) { \
|
if (str__ != NULL) { \
|
||||||
size_t size__ = strlen(str__); \
|
size_t size__ = strlen(str__); \
|
||||||
if (size__ > (SIZE)) { \
|
if (size__ > usize__) { \
|
||||||
size__ = (SIZE); \
|
size__ = usize__; \
|
||||||
} \
|
} \
|
||||||
StringMemcat(BLK, str__, size__); \
|
StringMemcat(BLK, str__, size__); \
|
||||||
} \
|
} \
|
||||||
|
|||||||
Reference in New Issue
Block a user