aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-11-02 14:20:34 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-11-02 14:20:34 +0100
commit53283adb24765a7afb4d6298661c3c1a8d6f5601 (patch)
tree70fcc968562a53787b3da7de7fe4050732a2cc0c
parent8131eea3dce5fba0dfb78e6083d1730423fad20b (diff)
downloadbusybox-w32-53283adb24765a7afb4d6298661c3c1a8d6f5601.tar.gz
busybox-w32-53283adb24765a7afb4d6298661c3c1a8d6f5601.tar.bz2
busybox-w32-53283adb24765a7afb4d6298661c3c1a8d6f5601.zip
include/libbb.h: mark malloc-returning functions with GCC attribute
function old new delta ash_main 1336 1365 +29 readcmd 1062 1072 +10 add_split_dependencies 707 717 +10 rtnl_talk 539 548 +9 normalize 165 174 +9 xmalloc_optname_optval 583 590 +7 test_main 247 253 +6 insert_bg_job 366 371 +5 dname_enc 391 395 +4 nslookup_main 165 168 +3 ifplugd_main 1099 1102 +3 tftpd_main 493 495 +2 make_new_session 413 415 +2 localcmd 274 276 +2 date_main 696 698 +2 tee_main 317 318 +1 setvar 183 184 +1 hash_find 233 234 +1 xrtnl_dump_filter 400 399 -1 prepend_new_eth_table 297 295 -2 unpack_Z_stream 1229 1226 -3 read_line_input 4823 4820 -3 do_load 523 520 -3 udhcp_run_script 669 665 -4 mkfs_vfat_main 1609 1605 -4 rtnl_rtprot_initialize 70 65 -5 procps_scan 1842 1835 -7 read_opt 873 865 -8 ifupdown_main 2133 2125 -8 mkfs_ext2_main 2492 2482 -10 logread_main 503 492 -11 svlogd_main 1441 1429 -12 rewrite 1032 1018 -14 fbsplash_main 917 903 -14 str2sockaddr 431 405 -26 unpack_lzma_stream 2705 2677 -28 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 18/18 up/down: 106/-163) Total: -57 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h69
-rw-r--r--include/platform.h9
2 files changed, 44 insertions, 34 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 955287c4d..bcf604a3c 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -331,12 +331,12 @@ void xmove_fd(int, int) FAST_FUNC;
331DIR *xopendir(const char *path) FAST_FUNC; 331DIR *xopendir(const char *path) FAST_FUNC;
332DIR *warn_opendir(const char *path) FAST_FUNC; 332DIR *warn_opendir(const char *path) FAST_FUNC;
333 333
334/* UNUSED: char *xmalloc_realpath(const char *path) FAST_FUNC; */ 334/* UNUSED: char *xmalloc_realpath(const char *path) FAST_FUNC RETURNS_MALLOC; */
335char *xmalloc_readlink(const char *path) FAST_FUNC; 335char *xmalloc_readlink(const char *path) FAST_FUNC RETURNS_MALLOC;
336char *xmalloc_readlink_or_warn(const char *path) FAST_FUNC; 336char *xmalloc_readlink_or_warn(const char *path) FAST_FUNC RETURNS_MALLOC;
337char *xrealloc_getcwd_or_warn(char *cwd) FAST_FUNC; 337char *xrealloc_getcwd_or_warn(char *cwd) FAST_FUNC RETURNS_MALLOC;
338 338
339char *xmalloc_follow_symlinks(const char *path) FAST_FUNC; 339char *xmalloc_follow_symlinks(const char *path) FAST_FUNC RETURNS_MALLOC;
340 340
341 341
342enum { 342enum {
@@ -514,23 +514,23 @@ int create_and_connect_stream_or_die(const char *peer, int port) FAST_FUNC;
514/* Connect to peer identified by lsa */ 514/* Connect to peer identified by lsa */
515int xconnect_stream(const len_and_sockaddr *lsa) FAST_FUNC; 515int xconnect_stream(const len_and_sockaddr *lsa) FAST_FUNC;
516/* Get local address of bound or accepted socket */ 516/* Get local address of bound or accepted socket */
517len_and_sockaddr *get_sock_lsa(int fd) FAST_FUNC; 517len_and_sockaddr *get_sock_lsa(int fd) FAST_FUNC RETURNS_MALLOC;
518/* Return malloc'ed len_and_sockaddr with socket address of host:port 518/* Return malloc'ed len_and_sockaddr with socket address of host:port
519 * Currently will return IPv4 or IPv6 sockaddrs only 519 * Currently will return IPv4 or IPv6 sockaddrs only
520 * (depending on host), but in theory nothing prevents e.g. 520 * (depending on host), but in theory nothing prevents e.g.
521 * UNIX socket address being returned, IPX sockaddr etc... 521 * UNIX socket address being returned, IPX sockaddr etc...
522 * On error does bb_error_msg and returns NULL */ 522 * On error does bb_error_msg and returns NULL */
523len_and_sockaddr* host2sockaddr(const char *host, int port) FAST_FUNC; 523len_and_sockaddr* host2sockaddr(const char *host, int port) FAST_FUNC RETURNS_MALLOC;
524/* Version which dies on error */ 524/* Version which dies on error */
525len_and_sockaddr* xhost2sockaddr(const char *host, int port) FAST_FUNC; 525len_and_sockaddr* xhost2sockaddr(const char *host, int port) FAST_FUNC RETURNS_MALLOC;
526len_and_sockaddr* xdotted2sockaddr(const char *host, int port) FAST_FUNC; 526len_and_sockaddr* xdotted2sockaddr(const char *host, int port) FAST_FUNC RETURNS_MALLOC;
527/* Same, useful if you want to force family (e.g. IPv6) */ 527/* Same, useful if you want to force family (e.g. IPv6) */
528#if !ENABLE_FEATURE_IPV6 528#if !ENABLE_FEATURE_IPV6
529#define host_and_af2sockaddr(host, port, af) host2sockaddr((host), (port)) 529#define host_and_af2sockaddr(host, port, af) host2sockaddr((host), (port))
530#define xhost_and_af2sockaddr(host, port, af) xhost2sockaddr((host), (port)) 530#define xhost_and_af2sockaddr(host, port, af) xhost2sockaddr((host), (port))
531#else 531#else
532len_and_sockaddr* host_and_af2sockaddr(const char *host, int port, sa_family_t af) FAST_FUNC; 532len_and_sockaddr* host_and_af2sockaddr(const char *host, int port, sa_family_t af) FAST_FUNC RETURNS_MALLOC;
533len_and_sockaddr* xhost_and_af2sockaddr(const char *host, int port, sa_family_t af) FAST_FUNC; 533len_and_sockaddr* xhost_and_af2sockaddr(const char *host, int port, sa_family_t af) FAST_FUNC RETURNS_MALLOC;
534#endif 534#endif
535/* Assign sin[6]_port member if the socket is an AF_INET[6] one, 535/* Assign sin[6]_port member if the socket is an AF_INET[6] one,
536 * otherwise no-op. Useful for ftp. 536 * otherwise no-op. Useful for ftp.
@@ -539,14 +539,14 @@ void set_nport(len_and_sockaddr *lsa, unsigned port) FAST_FUNC;
539/* Retrieve sin[6]_port or return -1 for non-INET[6] lsa's */ 539/* Retrieve sin[6]_port or return -1 for non-INET[6] lsa's */
540int get_nport(const struct sockaddr *sa) FAST_FUNC; 540int get_nport(const struct sockaddr *sa) FAST_FUNC;
541/* Reverse DNS. Returns NULL on failure. */ 541/* Reverse DNS. Returns NULL on failure. */
542char* xmalloc_sockaddr2host(const struct sockaddr *sa) FAST_FUNC; 542char* xmalloc_sockaddr2host(const struct sockaddr *sa) FAST_FUNC RETURNS_MALLOC;
543/* This one doesn't append :PORTNUM */ 543/* This one doesn't append :PORTNUM */
544char* xmalloc_sockaddr2host_noport(const struct sockaddr *sa) FAST_FUNC; 544char* xmalloc_sockaddr2host_noport(const struct sockaddr *sa) FAST_FUNC RETURNS_MALLOC;
545/* This one also doesn't fall back to dotted IP (returns NULL) */ 545/* This one also doesn't fall back to dotted IP (returns NULL) */
546char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa) FAST_FUNC; 546char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa) FAST_FUNC RETURNS_MALLOC;
547/* inet_[ap]ton on steroids */ 547/* inet_[ap]ton on steroids */
548char* xmalloc_sockaddr2dotted(const struct sockaddr *sa) FAST_FUNC; 548char* xmalloc_sockaddr2dotted(const struct sockaddr *sa) FAST_FUNC RETURNS_MALLOC;
549char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa) FAST_FUNC; 549char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa) FAST_FUNC RETURNS_MALLOC;
550// "old" (ipv4 only) API 550// "old" (ipv4 only) API
551// users: traceroute.c hostname.c - use _list_ of all IPs 551// users: traceroute.c hostname.c - use _list_ of all IPs
552struct hostent *xgethostbyname(const char *name) FAST_FUNC; 552struct hostent *xgethostbyname(const char *name) FAST_FUNC;
@@ -564,15 +564,16 @@ ssize_t recv_from_to(int fd, void *buf, size_t len, int flags,
564 struct sockaddr *to, 564 struct sockaddr *to,
565 socklen_t sa_size) FAST_FUNC; 565 socklen_t sa_size) FAST_FUNC;
566 566
567char *xstrdup(const char *s) FAST_FUNC; 567
568char *xstrndup(const char *s, int n) FAST_FUNC; 568char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC;
569char *xstrndup(const char *s, int n) FAST_FUNC RETURNS_MALLOC;
569void overlapping_strcpy(char *dst, const char *src) FAST_FUNC; 570void overlapping_strcpy(char *dst, const char *src) FAST_FUNC;
570char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC; 571char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC;
571char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC; 572char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC;
572/* Guaranteed to NOT be a macro (smallest code). Saves nearly 2k on uclibc. 573/* Guaranteed to NOT be a macro (smallest code). Saves nearly 2k on uclibc.
573 * But potentially slow, don't use in one-billion-times loops */ 574 * But potentially slow, don't use in one-billion-times loops */
574int bb_putchar(int ch) FAST_FUNC; 575int bb_putchar(int ch) FAST_FUNC;
575char *xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; 576char *xasprintf(const char *format, ...) __attribute__ ((format(printf, 1, 2))) FAST_FUNC RETURNS_MALLOC;
576/* Prints unprintable chars ch as ^C or M-c to file 577/* Prints unprintable chars ch as ^C or M-c to file
577 * (M-c is used only if ch is ORed with PRINTABLE_META), 578 * (M-c is used only if ch is ORed with PRINTABLE_META),
578 * else it is printed as-is (except for ch = 0x9b) */ 579 * else it is printed as-is (except for ch = 0x9b) */
@@ -592,9 +593,9 @@ void fputc_printable(int ch, FILE *file) FAST_FUNC;
592 593
593/* dmalloc will redefine these to it's own implementation. It is safe 594/* dmalloc will redefine these to it's own implementation. It is safe
594 * to have the prototypes here unconditionally. */ 595 * to have the prototypes here unconditionally. */
595void *malloc_or_warn(size_t size) FAST_FUNC; 596void *malloc_or_warn(size_t size) FAST_FUNC RETURNS_MALLOC;
596void *xmalloc(size_t size) FAST_FUNC; 597void *xmalloc(size_t size) FAST_FUNC RETURNS_MALLOC;
597void *xzalloc(size_t size) FAST_FUNC; 598void *xzalloc(size_t size) FAST_FUNC RETURNS_MALLOC;
598void *xrealloc(void *old, size_t size) FAST_FUNC; 599void *xrealloc(void *old, size_t size) FAST_FUNC;
599/* After xrealloc_vector(v, 4, idx) it's ok to use 600/* After xrealloc_vector(v, 4, idx) it's ok to use
600 * at least v[idx] and v[idx+1], for all idx values. 601 * at least v[idx] and v[idx+1], for all idx values.
@@ -617,16 +618,16 @@ extern ssize_t open_read_close(const char *filename, void *buf, size_t maxsz) FA
617// Reads one line a-la fgets (but doesn't save terminating '\n'). 618// Reads one line a-la fgets (but doesn't save terminating '\n').
618// Reads byte-by-byte. Useful when it is important to not read ahead. 619// Reads byte-by-byte. Useful when it is important to not read ahead.
619// Bytes are appended to pfx (which must be malloced, or NULL). 620// Bytes are appended to pfx (which must be malloced, or NULL).
620extern char *xmalloc_reads(int fd, char *pfx, size_t *maxsz_p) FAST_FUNC; 621extern char *xmalloc_reads(int fd, char *pfx, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
621/* Reads block up to *maxsz_p (default: INT_MAX - 4095) */ 622/* Reads block up to *maxsz_p (default: INT_MAX - 4095) */
622extern void *xmalloc_read(int fd, size_t *maxsz_p) FAST_FUNC; 623extern void *xmalloc_read(int fd, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
623/* Returns NULL if file can't be opened (default max size: INT_MAX - 4095) */ 624/* Returns NULL if file can't be opened (default max size: INT_MAX - 4095) */
624extern void *xmalloc_open_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC; 625extern void *xmalloc_open_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
625/* Autodetects .gz etc */ 626/* Autodetects .gz etc */
626extern int open_zipped(const char *fname) FAST_FUNC; 627extern int open_zipped(const char *fname) FAST_FUNC;
627extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC; 628extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
628/* Never returns NULL */ 629/* Never returns NULL */
629extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC; 630extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
630 631
631extern ssize_t safe_write(int fd, const void *buf, size_t count) FAST_FUNC; 632extern ssize_t safe_write(int fd, const void *buf, size_t count) FAST_FUNC;
632// NB: will return short write on error, not -1, 633// NB: will return short write on error, not -1,
@@ -645,17 +646,17 @@ extern void xprint_and_close_file(FILE *file) FAST_FUNC;
645extern char *bb_get_chunk_from_file(FILE *file, int *end) FAST_FUNC; 646extern char *bb_get_chunk_from_file(FILE *file, int *end) FAST_FUNC;
646extern char *bb_get_chunk_with_continuation(FILE *file, int *end, int *lineno) FAST_FUNC; 647extern char *bb_get_chunk_with_continuation(FILE *file, int *end, int *lineno) FAST_FUNC;
647/* Reads up to (and including) TERMINATING_STRING: */ 648/* Reads up to (and including) TERMINATING_STRING: */
648extern char *xmalloc_fgets_str(FILE *file, const char *terminating_string) FAST_FUNC; 649extern char *xmalloc_fgets_str(FILE *file, const char *terminating_string) FAST_FUNC RETURNS_MALLOC;
649/* Same, with limited max size, and returns the length (excluding NUL): */ 650/* Same, with limited max size, and returns the length (excluding NUL): */
650extern char *xmalloc_fgets_str_len(FILE *file, const char *terminating_string, size_t *maxsz_p) FAST_FUNC; 651extern char *xmalloc_fgets_str_len(FILE *file, const char *terminating_string, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
651/* Chops off TERMINATING_STRING from the end: */ 652/* Chops off TERMINATING_STRING from the end: */
652extern char *xmalloc_fgetline_str(FILE *file, const char *terminating_string) FAST_FUNC; 653extern char *xmalloc_fgetline_str(FILE *file, const char *terminating_string) FAST_FUNC RETURNS_MALLOC;
653/* Reads up to (and including) "\n" or NUL byte: */ 654/* Reads up to (and including) "\n" or NUL byte: */
654extern char *xmalloc_fgets(FILE *file) FAST_FUNC; 655extern char *xmalloc_fgets(FILE *file) FAST_FUNC RETURNS_MALLOC;
655/* Chops off '\n' from the end, unlike fgets: */ 656/* Chops off '\n' from the end, unlike fgets: */
656extern char *xmalloc_fgetline(FILE *file) FAST_FUNC; 657extern char *xmalloc_fgetline(FILE *file) FAST_FUNC RETURNS_MALLOC;
657/* Same, but doesn't try to conserve space (may have some slack after the end) */ 658/* Same, but doesn't try to conserve space (may have some slack after the end) */
658/* extern char *xmalloc_fgetline_fast(FILE *file) FAST_FUNC; */ 659/* extern char *xmalloc_fgetline_fast(FILE *file) FAST_FUNC RETURNS_MALLOC; */
659 660
660extern void die_if_ferror(FILE *file, const char *msg) FAST_FUNC; 661extern void die_if_ferror(FILE *file, const char *msg) FAST_FUNC;
661extern void die_if_ferror_stdout(void) FAST_FUNC; 662extern void die_if_ferror_stdout(void) FAST_FUNC;
@@ -1157,7 +1158,7 @@ const char *nth_string(const char *strings, int n) FAST_FUNC;
1157extern void print_login_issue(const char *issue_file, const char *tty) FAST_FUNC; 1158extern void print_login_issue(const char *issue_file, const char *tty) FAST_FUNC;
1158extern void print_login_prompt(void) FAST_FUNC; 1159extern void print_login_prompt(void) FAST_FUNC;
1159 1160
1160char *xmalloc_ttyname(int fd) FAST_FUNC; 1161char *xmalloc_ttyname(int fd) FAST_FUNC RETURNS_MALLOC;
1161/* NB: typically you want to pass fd 0, not 1. Think 'applet | grep something' */ 1162/* NB: typically you want to pass fd 0, not 1. Think 'applet | grep something' */
1162int get_terminal_width_height(int fd, unsigned *width, unsigned *height) FAST_FUNC; 1163int get_terminal_width_height(int fd, unsigned *width, unsigned *height) FAST_FUNC;
1163 1164
diff --git a/include/platform.h b/include/platform.h
index 67b04f8cb..54bc27d5b 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -60,6 +60,15 @@
60 60
61#define UNUSED_PARAM __attribute__ ((__unused__)) 61#define UNUSED_PARAM __attribute__ ((__unused__))
62#define NORETURN __attribute__ ((__noreturn__)) 62#define NORETURN __attribute__ ((__noreturn__))
63/* "The malloc attribute is used to tell the compiler that a function
64 * may be treated as if any non-NULL pointer it returns cannot alias
65 * any other pointer valid when the function returns. This will often
66 * improve optimization. Standard functions with this property include
67 * malloc and calloc. realloc-like functions have this property as long
68 * as the old pointer is never referred to (including comparing it
69 * to the new pointer) after the function returns a non-NULL value."
70 */
71#define RETURNS_MALLOC __attribute__ ((malloc))
63#define PACKED __attribute__ ((__packed__)) 72#define PACKED __attribute__ ((__packed__))
64#define ALIGNED(m) __attribute__ ((__aligned__(m))) 73#define ALIGNED(m) __attribute__ ((__aligned__(m)))
65 74