Commit Graph

17 Commits

Author SHA1 Message Date
Kurtis Rader
79f342b954 lint cleanup: eliminate "redundant" errors
This removes some pointless parentheses but the primary focus is removing
redundancies like unnecessary "else" clauses.
2016-05-04 15:32:04 -07:00
Kurtis Rader
fc44cffac5 restyle switch blocks to match project style
I missed restyling a few "switch" blocks to make them consistent with the rest
of the code base. This fixes that oversight. This should be the final step in
restyling the C++ code to have a consistent style. This also includes a few
trivial cleanups elsewhere.

I also missed restyling the "complete" module when working my way from a to z
so this final change includes restyling that module.

Total lint errors decreased 36%. Cppcheck errors went from 47 to 24. Oclint P2
errors went from 819 to 778. Oclint P3 errors went from 3252 to 1842.

Resolves #2902.
2016-05-03 17:14:56 -07:00
Kurtis Rader
1f06e5f0b9 add better support for IWYU and fix things
Remove the "make iwyu" build target. Move the functionality into the
recently introduced lint.fish script. Fix a lot, but not all, of the
include-what-you-use errors. Specifically, it fixes all of the IWYU errors
on my OS X server but only removes some of them on my Ubuntu 14.04 server.

Fixes #2957
2016-04-26 15:02:22 -07:00
Kurtis Rader
bd4622a0d0 make comments Xcode friendly
The OS X Xcode IDE has a weird requirement that block comments preceding a
function or class definition must begin with three slashes rather than two if
you want the comment displayed in the "Quick Help" window.
2016-04-19 18:22:44 -07:00
Kurtis Rader
61c0ca9dd9 restyle history code to match project style
Make the history code conform to the new style guide. Every change was
produced by clang-format (e.g., `make style`) with the exception of
comments which were manually reformatted.  That has to be done by hand
since clang-format leaves comments alone other than to reflow comment
lines to get them below the allowed line length.

The total number of lines is reduced by 313 lines (13%) in the two
affected files. Line count is generally a poor metric but in this
case it reflects an increase in information density without a loss in
readability. Furthermore, the standardization of braces, whitespace,
and comment style will make it easier for people to read the code.

This reduces the number of warnings by `make lint` from 168 to 87 (a 48%
decrease). Making it much easier to focus on the substantive lint issues.

Further improvements are possible. For example, many comments are not
very helpful (e.g., they point out the obvious) or provide insufficient
detail. But those are beyond the scope of this change.

This is the first step in resolving issue #2902.
2016-04-18 17:20:19 -07:00
Andreas Nordal
6495bd470d Fix memory leaks at exit found in tests
This fixes all memory leaks found by compiling with
clang++ -g -fsanitize=address and running the tests.

Method:
Ensure that memory is freed by the destructor of its respective container,
either by storing objects directly instead of by pointer, or implementing
the required destructor.
2016-03-27 17:40:48 -07:00
Kurtis Rader
c2f1df1d4a fix handling of non-ASCII chars in C locale
The relevant standards allow the mbtowc/mbrtowc functions to reject
non-ASCII characters (i.e., chars with the high bit set) when the locale
is C or POSIX.  The BSD libraries (e.g., on OS X) don't do this but
the GNU libraries (e.g., on Linux) do. Like most programs we need the
C/POSIX locales to allow arbitrary bytes. So explicitly check if we're
in a single-byte locale (which would also include ISO-8859 variants)
and simply pass-thru the chars without encoding or decoding.

Fixes #2802.
2016-03-20 18:47:38 -07:00
Jeff Kowalski
a7012648fe Improve error handling around fchown
Address the feedback from the prior commit:
- Change the sense of return value testing to match more common
comparison idiom
- Test result of fchmod as well as fchown
- Change sense of return value testing around wrename as well
- Include errno where possible in error message
2016-03-12 12:26:01 -08:00
Jeff Kowalski
46b9f263ac Handle return values from fchown
The function fchown is annotated with warn_unused_result.  As
formerly used in the code, it would emit a compiler warning
```warning: ignoring return value of ‘fchown’, declared with
attribute warn_unused_result [-Wunused-result]```

This commit notes the return value and emits appropriate error/logging
messages if the call fails, creating more traceable results and
satisfying the compiler.
2016-03-12 11:21:52 -08:00
ridiculousfish
1e7c3fe709 A few fixes suggested by Coverity Scan 2016-03-03 18:49:24 -08:00
ridiculousfish
10f3ea0008 Mark a bunch of constructors as explicit
This prevents undesired implicit conversions
2016-02-27 19:38:15 -08:00
Jeff Kowalski
226cdc6a28 Fix usage of history_filename 2015-10-16 07:40:04 +08:00
Jeff Kowalski
b13f0701a4 Migrate fish_history from config to data dir
New implementation of migration code within the history_t class will
copy the contents of the old fish_history found in the config directory
to its new location in the data directory.  The old file is left intact.

This is done only in the event that a fish_history is not already found in
the data directory ($XDG_DATA_HOME/fish or ~/.local/share/fish).
2015-10-16 07:40:04 +08:00
Jeff Kowalski
2971887bbd Access fish_history from $XDG_DATA_HOME
Add new functions path_get_data and path_create_data which parallel existing
functions path_get_config and path_create_data.  The new functions refer to
XDG_DATA_HOME, if it is defined, or ./local/share if not.

Modify history_filename to use the new function path_get_data.

As a consequence, fish_history will now be located in XDG_DATA_HOME,
not XDG_CONFIG_HOME.

Note that these changes mirror what is already used in
fish-shell/share/tools/create_manpage_completions.py, which stores the
completions in XDG_DATA_HOME

This change matches recommendations in the xdg basedir spec at
http://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
($XDG_DATA_HOME defines the base directory relative to which user specific data
files should be stored. If $XDG_DATA_HOME is either not set or empty, a default
equal to $HOME/.local/share should be used.)

It addresses suggestions from the following issues:

1. Don't put history in $XDG_CONFIG_HOME (closes #744)
   https://github.com/fish-shell/fish-shell/issues/744

2. Fish is placing non-config files in $XDG_CONFIG_HOME #1257
   https://github.com/fish-shell/fish-shell/issues/1257

3. Move non-config data out of $XDG_CONFIG_HOME #1669
   https://github.com/fish-shell/fish-shell/issues/1669
2015-10-16 07:39:49 +08:00
ridiculousfish
871a2088db Preserve existing file permissions when rewriting a history file
Fixes #2335
2015-09-26 02:19:51 -07:00
David Adam
3929e9de0e Merge branch 'master' into iwyu 2015-07-26 10:20:13 +08:00
ridiculousfish
b4f53143b0 Migrate source files into src/ directory
This change moves source files into a src/ directory,
and puts object files into an obj/ directory. The Makefile
and xcode project are updated accordingly.

Fixes #1866
2015-07-24 00:59:27 -07:00