Skip to content

Commit 3dab78e

Browse files
committed
xy.h 完全不再考虑内存分配失败的情况
1 parent b6b235b commit 3dab78e

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

lib/xy.h

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* | BingChunMoLi <bingchunmoli@bingchunmoli.com>
1010
* |
1111
* Created On : <2023-08-28>
12-
* Last Modified : <2026-03-17>
12+
* Last Modified : <2026-03-18>
1313
*
1414
*
1515
* xy: 襄阳、咸阳
@@ -18,12 +18,17 @@
1818
*
1919
* 该库的特点是混合多种编程语言风味 (绝大多数为 Ruby),每个 API
2020
* 均使用 @flavor 标注其参考依据
21+
*
22+
*
23+
* 说明:
24+
* 1. 完全不考虑OOM等内存分配失败的情况
25+
*
2126
* ------------------------------------------------------------*/
2227

2328
#ifndef XY_H
2429
#define XY_H
2530

26-
#define _XY_Version "v0.2.2.1-2026/03/17"
31+
#define _XY_Version "v0.2.2.2-2026/03/18"
2732
#define _XY_Maintain_URL "https://github.com/RubyMetric/chsrc/blob/dev/lib/xy.h"
2833
#define _XY_Maintain_URL2 "https://gitee.com/RubyMetric/chsrc/blob/dev/lib/xy.h"
2934

@@ -279,10 +284,9 @@ xy_str_gsub (const char *str, const char *pat, const char *replace)
279284
else
280285
break;
281286
}
282-
// puti(count); DEBUG 匹配次数
287+
// print(count); /* DEBUG 匹配次数 */
283288

284289
char *ret = malloc (unit * count + len + 1);
285-
if (!ret) return NULL;
286290
char *retcur = ret;
287291

288292
cur = str;
@@ -377,11 +381,6 @@ xy_strcat (unsigned int count, ...)
377381
ret = realloc (ret, al_cur);
378382
cur = ret + diff;
379383
}
380-
if (NULL == ret)
381-
{
382-
_xy_internal_warn ("xy_strcat(): No availble memory to allocate!");
383-
return NULL;
384-
}
385384
strcpy (cur, str);
386385
// puts(ret);
387386
cur += strlen (str);
@@ -743,11 +742,6 @@ xy_file_read (const char *path)
743742
rewind (fp);
744743

745744
char *buf = xy_malloc0 ((size_t) size + 1);
746-
if (!buf)
747-
{
748-
fclose (fp);
749-
return xy_strdup ("");
750-
}
751745

752746
size_t read_bytes = fread (buf, 1, (size_t) size, fp);
753747
if (read_bytes < (size_t) size && ferror (fp))
@@ -979,15 +973,14 @@ xy_run_iter_lines (const char *cmd, unsigned long n, bool (*func) (const char
979973
if (NULL == fgets (buf, size, stream))
980974
break;
981975
/* 存在换行的总是会把换行符读出来,删掉 */
982-
if (ret)
983-
free (ret);
976+
if (ret) free (ret); /* 上次读到的需要释放 */
984977
ret = xy_str_delete_suffix (buf, "\n");
985978
count += 1;
986979
if (n == count)
987980
break;
988981
if (func)
989982
{
990-
if (func (ret))
983+
if (func (ret))
991984
break;
992985
}
993986
}
@@ -1476,7 +1469,6 @@ XySeq_t*
14761469
xy_seq_new (void)
14771470
{
14781471
XySeq_t *seq = xy_malloc0 (sizeof (XySeq_t));
1479-
if (!seq) return NULL;
14801472

14811473
seq->first_item = NULL;
14821474
seq->last_item = NULL;

0 commit comments

Comments
 (0)