From owner-svn-src-all@FreeBSD.ORG Mon Apr 6 02:35:58 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9D76643E; Mon, 6 Apr 2015 02:35:58 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 87971FD0; Mon, 6 Apr 2015 02:35:58 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t362Zwqn017614; Mon, 6 Apr 2015 02:35:58 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t362ZtuS017607; Mon, 6 Apr 2015 02:35:55 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201504060235.t362ZtuS017607@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Mon, 6 Apr 2015 02:35:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r281132 - head/usr.bin/sort X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Apr 2015 02:35:58 -0000 Author: pfg Date: Mon Apr 6 02:35:55 2015 New Revision: 281132 URL: https://svnweb.freebsd.org/changeset/base/281132 Log: Revert (partial) r281123, r281125: sort: style knits / cleanups. Our style guide(9) specifies that in absence of local variables an empty line must be inserted. Pointed out by: eadler Modified: head/usr.bin/sort/bwstring.c head/usr.bin/sort/coll.c head/usr.bin/sort/file.c head/usr.bin/sort/mem.c head/usr.bin/sort/radixsort.c head/usr.bin/sort/sort.c head/usr.bin/sort/vsort.c Modified: head/usr.bin/sort/bwstring.c ============================================================================== --- head/usr.bin/sort/bwstring.c Mon Apr 6 01:53:47 2015 (r281131) +++ head/usr.bin/sort/bwstring.c Mon Apr 6 02:35:55 2015 (r281132) @@ -147,6 +147,7 @@ wide_str_coll(const wchar_t *s1, const w void bwsprintf(FILE *f, struct bwstring *bws, const char *prefix, const char *suffix) { + if (MB_CUR_MAX == 1) fprintf(f, "%s%s%s", prefix, bws->data.cstr, suffix); else @@ -155,17 +156,20 @@ bwsprintf(FILE *f, struct bwstring *bws, const void* bwsrawdata(const struct bwstring *bws) { + return (&(bws->data)); } size_t bwsrawlen(const struct bwstring *bws) { + return ((MB_CUR_MAX == 1) ? bws->len : SIZEOF_WCHAR_STRING(bws->len)); } size_t bws_memsize(const struct bwstring *bws) { + return ((MB_CUR_MAX == 1) ? (bws->len + 2 + sizeof(struct bwstring)) : (SIZEOF_WCHAR_STRING(bws->len + 1) + sizeof(struct bwstring))); } @@ -173,6 +177,7 @@ bws_memsize(const struct bwstring *bws) void bws_setlen(struct bwstring *bws, size_t newlen) { + if (bws && newlen != bws->len && newlen <= bws->len) { bws->len = newlen; if (MB_CUR_MAX == 1) @@ -212,6 +217,7 @@ bwsalloc(size_t sz) struct bwstring * bwsdup(const struct bwstring *s) { + if (s == NULL) return (NULL); else { @@ -233,6 +239,7 @@ bwsdup(const struct bwstring *s) struct bwstring * bwssbdup(const wchar_t *str, size_t len) { + if (str == NULL) return ((len == 0) ? bwsalloc(0) : NULL); else { @@ -313,6 +320,7 @@ bwscsbdup(const unsigned char *str, size void bwsfree(const struct bwstring *s) { + if (s) sort_free(s); } @@ -383,6 +391,7 @@ struct bwstring * bwsnocpy(struct bwstring *dst, const struct bwstring *src, size_t offset, size_t size) { + if (offset >= src->len) { dst->data.wstr[0] = 0; dst->len = 0; @@ -415,6 +424,7 @@ bwsnocpy(struct bwstring *dst, const str size_t bwsfwrite(struct bwstring *bws, FILE *f, bool zero_ended) { + if (MB_CUR_MAX == 1) { size_t len = bws->len; @@ -904,6 +914,7 @@ bwstod(struct bwstring *s0, bool *empty) int bws_month_score(const struct bwstring *s0) { + if (MB_CUR_MAX == 1) { const unsigned char *end, *s; size_t len; @@ -1109,6 +1120,7 @@ dictionary_order(struct bwstring *str) struct bwstring * ignore_case(struct bwstring *str) { + if (MB_CUR_MAX == 1) { unsigned char *end, *s; @@ -1136,6 +1148,7 @@ ignore_case(struct bwstring *str) void bws_disorder_warnx(struct bwstring *s, const char *fn, size_t pos) { + if (MB_CUR_MAX == 1) warnx("%s:%zu: disorder: %s", fn, pos + 1, s->data.cstr); else Modified: head/usr.bin/sort/coll.c ============================================================================== --- head/usr.bin/sort/coll.c Mon Apr 6 01:53:47 2015 (r281131) +++ head/usr.bin/sort/coll.c Mon Apr 6 02:35:55 2015 (r281132) @@ -93,6 +93,7 @@ key_hint_size(void) size_t keys_array_size(void) { + return (keys_num * (sizeof(struct key_value) + key_hint_size())); } @@ -102,6 +103,7 @@ keys_array_size(void) void clean_keys_array(const struct bwstring *s, struct keys_array *ka) { + if (ka) { for (size_t i = 0; i < keys_num; ++i) if (ka->key[i].k && ka->key[i].k != s) @@ -116,6 +118,7 @@ clean_keys_array(const struct bwstring * void set_key_on_keys_array(struct keys_array *ka, struct bwstring *s, size_t ind) { + if (ka && keys_num > ind) { struct key_value *kv; @@ -170,6 +173,7 @@ sort_list_item_size(struct sort_list_ite static void sort_list_item_make_key(struct sort_list_item *si) { + preproc(si->str, &(si->ka)); } @@ -180,6 +184,7 @@ sort_list_item_make_key(struct sort_list void sort_list_item_set(struct sort_list_item *si, struct bwstring *str) { + if (si) { clean_keys_array(si->str, &(si->ka)); if (si->str) { @@ -202,6 +207,7 @@ sort_list_item_set(struct sort_list_item void sort_list_item_clean(struct sort_list_item *si) { + if (si) { clean_keys_array(si->str, &(si->ka)); if (si->str) { @@ -242,6 +248,7 @@ skip_cols_to_start(const struct bwstring static size_t skip_fields_to_start(const struct bwstring *s, size_t fields, bool *empty_field) { + if (fields < 2) { if (BWSLEN(s) == 0) *empty_field = true; @@ -290,6 +297,7 @@ static void find_field_start(const struct bwstring *s, struct key_specs *ks, size_t *field_start, size_t *key_start, bool *empty_field, bool *empty_key) { + *field_start = skip_fields_to_start(s, ks->f1, empty_field); if (!*empty_field) *key_start = skip_cols_to_start(s, ks->c1, *field_start, @@ -386,6 +394,7 @@ cut_field(const struct bwstring *s, stru int preproc(struct bwstring *s, struct keys_array *ka) { + if (sort_opts_vals.kflag) for (size_t i = 0; i < keys_num; i++) { struct bwstring *key; @@ -440,6 +449,7 @@ preproc(struct bwstring *s, struct keys_ cmpcoll_t get_sort_func(struct sort_mods *sm) { + if (sm->nflag) return (numcoll); else if (sm->hflag) @@ -492,6 +502,7 @@ key_coll(struct keys_array *ps1, struct int top_level_str_coll(const struct bwstring *s1, const struct bwstring *s2) { + if (default_sort_mods->rflag) { const struct bwstring *tmp; @@ -580,15 +591,16 @@ list_coll_offset(struct sort_list_item * int list_coll(struct sort_list_item **ss1, struct sort_list_item **ss2) { + return (list_coll_offset(ss1, ss2, 0)); } -#define LSCDEF(N) \ -static int \ -list_coll_##N(struct sort_list_item **ss1, struct sort_list_item **ss2) \ -{ \ - \ - return (list_coll_offset(ss1, ss2, N)); \ +#define LSCDEF(N) \ +static int \ +list_coll_##N(struct sort_list_item **ss1, struct sort_list_item **ss2) \ +{ \ + \ + return (list_coll_offset(ss1, ss2, N)); \ } LSCDEF(1) @@ -634,6 +646,7 @@ get_list_call_func(size_t offset) int list_coll_by_str_only(struct sort_list_item **ss1, struct sort_list_item **ss2) { + return (top_level_str_coll(((*ss1)->str), ((*ss2)->str))); } @@ -771,6 +784,7 @@ wstrcoll(struct key_value *kv1, struct k static inline int cmpsuffix(unsigned char si1, unsigned char si2) { + return ((char)si1 - (char)si2); } @@ -936,6 +950,7 @@ numcoll_impl(struct key_value *kv1, stru static int numcoll(struct key_value *kv1, struct key_value *kv2, size_t offset) { + return (numcoll_impl(kv1, kv2, offset, false)); } @@ -945,6 +960,7 @@ numcoll(struct key_value *kv1, struct ke static int hnumcoll(struct key_value *kv1, struct key_value *kv2, size_t offset) { + return (numcoll_impl(kv1, kv2, offset, true)); } @@ -1030,6 +1046,7 @@ versioncoll(struct key_value *kv1, struc static inline bool huge_minus(double d, int err1) { + if (err1 == ERANGE) if (d == -HUGE_VAL || d == -HUGE_VALF || d == -HUGE_VALL) return (+1); @@ -1043,6 +1060,7 @@ huge_minus(double d, int err1) static inline bool huge_plus(double d, int err1) { + if (err1 == ERANGE) if (d == HUGE_VAL || d == HUGE_VALF || d == HUGE_VALL) return (+1); @@ -1056,6 +1074,7 @@ huge_plus(double d, int err1) static bool is_nan(double d) { + return ((d == NAN) || (isnan(d))); } @@ -1065,6 +1084,7 @@ is_nan(double d) static int cmp_nans(double d1, double d2) { + if (d1 < d2) return (-1); if (d2 > d2) Modified: head/usr.bin/sort/file.c ============================================================================== --- head/usr.bin/sort/file.c Mon Apr 6 01:53:47 2015 (r281131) +++ head/usr.bin/sort/file.c Mon Apr 6 02:35:55 2015 (r281132) @@ -125,6 +125,7 @@ static void mt_sort(struct sort_list *li void init_tmp_files(void) { + LIST_INIT(&tmp_files); sem_init(&tmp_files_sem, 0, 1); } @@ -135,6 +136,7 @@ init_tmp_files(void) void tmp_file_atexit(const char *tmp_file) { + if (tmp_file) { sem_wait(&tmp_files_sem); struct CLEANABLE_FILE *item = @@ -246,6 +248,7 @@ new_tmp_file_name(void) void file_list_init(struct file_list *fl, bool tmp) { + if (fl) { fl->count = 0; fl->sz = 0; @@ -260,6 +263,7 @@ file_list_init(struct file_list *fl, boo void file_list_add(struct file_list *fl, char *fn, bool allocate) { + if (fl && fn) { if (fl->count >= fl->sz || (fl->fns == NULL)) { fl->sz = (fl->sz) * 2 + 1; @@ -277,6 +281,7 @@ file_list_add(struct file_list *fl, char void file_list_populate(struct file_list *fl, int argc, char **argv, bool allocate) { + if (fl && argv) { int i; @@ -292,6 +297,7 @@ file_list_populate(struct file_list *fl, void file_list_clean(struct file_list *fl) { + if (fl) { if (fl->fns) { size_t i; @@ -319,6 +325,7 @@ file_list_clean(struct file_list *fl) void sort_list_init(struct sort_list *l) { + if (l) { l->count = 0; l->size = 0; @@ -333,6 +340,7 @@ sort_list_init(struct sort_list *l) void sort_list_add(struct sort_list *l, struct bwstring *str) { + if (l && str) { size_t indx = l->count; @@ -358,6 +366,7 @@ sort_list_add(struct sort_list *l, struc void sort_list_clean(struct sort_list *l) { + if (l) { if (l->list) { size_t i; @@ -388,6 +397,7 @@ sort_list_clean(struct sort_list *l) void sort_list_dump(struct sort_list *l, const char *fn) { + if (l && fn) { FILE *f; @@ -823,6 +833,7 @@ file_reader_readline(struct file_reader static void file_reader_clean(struct file_reader *fr) { + if (fr) { if (fr->mmapaddr) munmap(fr->mmapaddr, fr->mmapsize); @@ -847,6 +858,7 @@ file_reader_clean(struct file_reader *fr void file_reader_free(struct file_reader *fr) { + if (fr) { file_reader_clean(fr); sort_free(fr); @@ -894,6 +906,7 @@ procfile(const char *fsrc, struct sort_l static int file_header_cmp(struct file_header *f1, struct file_header *f2) { + if (f1 == f2) return (0); else { @@ -918,6 +931,7 @@ file_header_cmp(struct file_header *f1, static void file_header_init(struct file_header **fh, const char *fn, size_t file_pos) { + if (fh && fn) { struct bwstring *line; @@ -946,6 +960,7 @@ file_header_init(struct file_header **fh static void file_header_close(struct file_header **fh) { + if (fh && *fh) { if ((*fh)->fr) { file_reader_free((*fh)->fr); @@ -983,6 +998,7 @@ file_header_swap(struct file_header **fh static void file_header_heap_swim(struct file_header **fh, size_t indx) { + if (indx > 0) { size_t parent_index; @@ -1032,6 +1048,7 @@ file_header_heap_sink(struct file_header static void file_header_list_rearrange_from_header(struct file_header **fh, size_t size) { + file_header_heap_sink(fh, 0, size); } @@ -1041,6 +1058,7 @@ file_header_list_rearrange_from_header(s static void file_header_list_push(struct file_header *f, struct file_header **fh, size_t size) { + fh[size++] = f; file_header_heap_swim(fh, size - 1); } @@ -1056,6 +1074,7 @@ struct last_printed static void file_header_print(struct file_header *fh, FILE *f_out, struct last_printed *lp) { + if (fh && fh->fr && f_out && fh->si && fh->si->str) { if (sort_opts_vals.uflag) { if ((lp->str == NULL) || (str_list_coll(lp->str, &(fh->si)))) { @@ -1075,6 +1094,7 @@ file_header_print(struct file_header *fh static void file_header_read_next(struct file_header *fh) { + if (fh && fh->fr) { struct bwstring *tmp; @@ -1132,6 +1152,7 @@ file_headers_merge(size_t fnum, struct f static void merge_files_array(size_t argc, char **argv, const char *fn_out) { + if (argv && fn_out) { struct file_header **fh; FILE *f_out; @@ -1164,6 +1185,7 @@ merge_files_array(size_t argc, char **ar static int shrink_file_list(struct file_list *fl) { + if ((fl == NULL) || (size_t) (fl->count) < max_open_files) return (0); else { @@ -1208,6 +1230,7 @@ shrink_file_list(struct file_list *fl) void merge_files(struct file_list *fl, const char *fn_out) { + if (fl && fn_out) { while (shrink_file_list(fl)); @@ -1218,6 +1241,7 @@ merge_files(struct file_list *fl, const static const char * get_sort_method_name(int sm) { + if (sm == SORT_MERGESORT) return "mergesort"; else if (sort_opts_vals.sort_method == SORT_RADIXSORT) Modified: head/usr.bin/sort/mem.c ============================================================================== --- head/usr.bin/sort/mem.c Mon Apr 6 01:53:47 2015 (r281131) +++ head/usr.bin/sort/mem.c Mon Apr 6 02:35:55 2015 (r281132) @@ -53,6 +53,7 @@ sort_malloc(size_t size) void sort_free(const void *ptr) { + if (ptr) free(__DECONST(void *, ptr)); } Modified: head/usr.bin/sort/radixsort.c ============================================================================== --- head/usr.bin/sort/radixsort.c Mon Apr 6 01:53:47 2015 (r281131) +++ head/usr.bin/sort/radixsort.c Mon Apr 6 02:35:55 2015 (r281132) @@ -231,6 +231,7 @@ add_to_sublevel(struct sort_level *sl, s static inline void add_leaf(struct sort_level *sl, struct sort_list_item *item) { + if (++(sl->leaves_num) > sl->leaves_sz) { sl->leaves_sz = sl->leaves_num + 128; sl->leaves = sort_realloc(sl->leaves, @@ -269,6 +270,7 @@ place_item(struct sort_level *sl, size_t static void free_sort_level(struct sort_level *sl) { + if (sl) { if (sl->leaves) sort_free(sl->leaves); @@ -306,7 +308,7 @@ run_sort_level_next(struct sort_level *s sl->sublevels = NULL; } - switch (sl->tosort_num) { + switch (sl->tosort_num){ case 0: goto end; case (1): Modified: head/usr.bin/sort/sort.c ============================================================================== --- head/usr.bin/sort/sort.c Mon Apr 6 01:53:47 2015 (r281131) +++ head/usr.bin/sort/sort.c Mon Apr 6 02:35:55 2015 (r281132) @@ -196,6 +196,7 @@ void fix_obsolete_keys(int *argc, char * static bool sort_modifier_empty(struct sort_mods *sm) { + if (sm == NULL) return (true); return (!(sm->Mflag || sm->Vflag || sm->nflag || sm->gflag || @@ -305,6 +306,7 @@ set_hw_params(void) static void conv_mbtowc(wchar_t *wc, const char *c, const wchar_t def) { + if (wc && c) { int res; @@ -384,6 +386,7 @@ set_tmpdir(void) static unsigned long long parse_memory_buffer_value(const char *value) { + if (value == NULL) return (available_free_memory); else { @@ -446,6 +449,7 @@ static void sig_handler(int sig __unused, siginfo_t *siginfo __unused, void *context __unused) { + clear_tmp_files(); exit(-1); } @@ -506,6 +510,7 @@ set_signal_handler(void) static void unknown(const char *what) { + errx(2, "%s: %s", getstr(3), what); } @@ -518,7 +523,7 @@ check_mutually_exclusive_flags(char c, b int fo_index, mec; bool found_others, found_this; - found_others = found_this = false; + found_others = found_this =false; fo_index = 0; for (int i = 0; i < NUMBER_OF_MUTUALLY_EXCLUSIVE_FLAGS; i++) { @@ -546,6 +551,7 @@ check_mutually_exclusive_flags(char c, b static void set_sort_opts(void) { + memset(&default_sort_mods_object, 0, sizeof(default_sort_mods_object)); memset(&sort_opts_vals, 0, sizeof(sort_opts_vals)); @@ -559,6 +565,7 @@ set_sort_opts(void) static bool set_sort_modifier(struct sort_mods *sm, int c) { + if (sm) { switch (c){ case 'b': Modified: head/usr.bin/sort/vsort.c ============================================================================== --- head/usr.bin/sort/vsort.c Mon Apr 6 01:53:47 2015 (r281131) +++ head/usr.bin/sort/vsort.c Mon Apr 6 02:35:55 2015 (r281132) @@ -40,18 +40,21 @@ __FBSDID("$FreeBSD$"); static inline bool isdigit_clocale(wchar_t c) { + return (c >= L'0' && c <= L'9'); } static inline bool isalpha_clocale(wchar_t c) { + return ((c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z')); } static inline bool isalnum_clocale(wchar_t c) { + return ((c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z') || (c >= L'0' && c <= L'9')); } @@ -112,6 +115,7 @@ find_suffix(bwstring_iterator si, bwstri static inline int cmp_chars(wchar_t c1, wchar_t c2) { + if (c1 == c2) return (0);