Gerhard Sittig [Sat, 10 Feb 2018 09:26:23 +0000 (10:26 +0100)]
hameg-hmo: fix potential memory leak
Make sure to release the allocated "pod enabled" memory, too, when SCPI
communication during channel setup fails. Defer the return with an error
(instead of duplicating the free() invocation).
Gerhard Sittig [Sat, 10 Feb 2018 09:18:20 +0000 (10:18 +0100)]
output/srzip: fix potential "use after free"
The compiler marks a potential use after free, which the current
implementation won't trigger. The error only occurs when a sigrok
channel is neither logic nor analog.
Address the issue nevertheless, to silence the compiler warning, and to
protect against possible programming errors when a future implementation
should support more channel types.
Gerhard Sittig [Sun, 23 Oct 2016 10:12:33 +0000 (12:12 +0200)]
output/wav: fixup coding style nits, adjust data types
Fixup unbalanced braces for more complex if statements, to better
reflect the project's official coding style.
Adjust data types in the float_to_le() routine. A float value gets
copied to a buffer of bytes (uint8_t). Don't use 'char' on the other
side of assignments, to not assume a specific width for char, and to
avoid potential signedness issues. Copy from bytes to bytes instead.
Gerhard Sittig [Sun, 23 Oct 2016 09:55:07 +0000 (11:55 +0200)]
output/wav: change default for scale factor from 0.0 to 1.0
The WAV output module supports an optional 'scale' factor, in its
absence the samples will pass unmodified. The builtin help text is
unexpected, and reads:
Gerhard Sittig [Sun, 4 Feb 2018 22:17:39 +0000 (23:17 +0100)]
output/vcd: assume packed input data image, unbreak 2nd+ channel
The previous implementation only emitted data for the first enabled
channels, and "saw no changes" after emission of the initial value for
channels on positions that followed a disabled channel.
Assume that the received data from the session bus communicates the bits
of enabled channels in a packed representation. Skip the mapping of
output bit indices to sigrok channel numbers.
This fixes the remaining part of bug #519.
Tested by inspecting in gtkwave the result of command:
$ sigrok-cli -d demo -C D1,D3,D6 -c samplerate=2M --samples 2500 -O vcd -o trace.vcd
When we find that all input sources (device drivers, and input modules)
provide a dense bit field, all of the mapping logic can get removed
here. This commit just quickly disables the logic.
Gerhard Sittig [Sun, 4 Feb 2018 22:05:59 +0000 (23:05 +0100)]
output/vcd: assign adjacent names to enabled channels
Identifiers for channels in the VCD header section could be "sparse"
when sigrok channels were disabled. Make sure to not assign names to
disabled channels. This will e.g. assign !, ", and # to channels D1, D3,
and D6, when D0, D2, D4-D5, and D7 are disabled.
Gerhard Sittig [Sun, 4 Feb 2018 21:26:23 +0000 (22:26 +0100)]
several DMMs: set DC flag for diode mode
Few DMM drivers already did it. This commit adjusts the remaining DMM
drivers, to set the "DC" flag for measurements in diode mode.
This fixes bug #144.
Although I don't have the hardware to test, the nature of the change and
the arrangement of driver code suggests it's good. When a meter already
communicated the "DC" status, the change does nothing and won't harm.
The change ensures "DC" is flagged for those meters which previously
didn't, which is desirable.
Gerhard Sittig [Sun, 4 Feb 2018 19:17:08 +0000 (20:17 +0100)]
strutil: accept trailing whitespace after number text
Some SCPI based drivers fail to convert response data, because strutil
conversion helpers sr_atol() and sr_atof() don't like trailing spaces
after the number's text that successfully got converted.
It's yet to get determined whether all call sites of the conversion
routines like their eating adjacent whitespace. But given that the
conversion routine explicitly checks for end of the string after the
number, no call site should expect or even depend on trailing text to
keep its whitespace.
Gerhard Sittig [Sun, 4 Feb 2018 18:50:25 +0000 (19:50 +0100)]
strutil: support tera/peta/exa suffixes in symbolic size specs
Synchronize sr_parse_sizestring() with sr_si_string_u64() capabilities.
Add support for the T/P/E suffixes. Since this conversion helper deals
with integer values exclusively, there is no issue with case insensitive
matches. The value cannot be pico. Neither is there an ambiguity with
the 10e6 notation.
This addresses bug #763.
Fix a style nit while we are here. Put braces around both arms of a
complex conditional.
Gerhard Sittig [Sun, 4 Feb 2018 15:18:03 +0000 (16:18 +0100)]
beaglelogic: silence compiler warning
Explicitly assign NULL to param to avoid the "may be used uninitialized"
warning reported in bug #1094. Behaviour remains unchanged. All references
to the variable were under "if (!conn)", and the assigning arm of the
branch checked for "if (!param)" after assignment. So the error could
not happen, but compilers may not have noticed depending on the width of
their scope during compilation.
Move the initialization of 'conn' closer to the conditional assignment,
such that all paths are seen in one spot during maintenance.
Gerhard Sittig [Mon, 29 Jan 2018 19:10:36 +0000 (20:10 +0100)]
log: flush log lines, to cope with non-terminal output (pipes)
Although log messages are terminated by a line feed, output still might
get buffered when the program does not talk to a terminal (that it is
aware of). Add an fflush(3) call to the printf(3) sequence such that log
output will immediately show up when writing to pipes or sockets, too.
Gerhard Sittig [Sun, 26 Mar 2017 13:46:37 +0000 (15:46 +0200)]
backend: fixup resource leak in sr_init() error code path
Early sr_init() steps can just 'return' fine. After allocation of the
'context' memory, make all error paths 'goto done' before returning,
to undo the memory allocation.
Gerhard Sittig [Sun, 28 Jan 2018 17:58:19 +0000 (18:58 +0100)]
srzip: don't access non-existing option
The srzip output module dropped support for the "filename" option in
commit 37875f750614 on 2015-07-30, but still used to assign to slot
options[0] which clobbers the array's sentinel. Remove those accesses
to the non-existing option.
Uwe Hermann [Fri, 9 Feb 2018 20:26:38 +0000 (21:26 +0100)]
hantek-4032l: Fix a compiler warning.
api.c: In function 'config_set':
api.c:352:5: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'uint64_t' [-Wformat=]
sr_err("invalid sample range 2k...64M: %ld",
^
Uwe Hermann [Fri, 9 Feb 2018 20:25:18 +0000 (21:25 +0100)]
beaglelogic: Fix a compiler warning.
beaglelogic_tcp.c: In function 'beaglelogic_tcp_send_cmd':
beaglelogic_tcp.c:114:3: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'size_t' [-Wformat=]
sr_dbg("Only sent %d/%lu bytes of command: '%s'.", out,
^
Gerhard Sittig [Fri, 9 Feb 2018 18:23:31 +0000 (19:23 +0100)]
ols, pipistrello-ols: silence "assigned, not used" compiler warning
Each code path either assigns to 'flags', or leaves the routine. There
is no potential path that leaves the variable at the initially assigned
value, so the assignment took no effect. Remove it.
Nit: Trim the source code line length while we are here.
Gerhard Sittig [Fri, 9 Feb 2018 18:17:13 +0000 (19:17 +0100)]
motech-lps-30x: fix several compiler warnings
Check pointers' validity before dereferencing them. Explicitly assign a
default value to variables, before conversion routines conditionally
assign the "real" value (and don't in case of conversion errors). This
avoids processing "garbage" data.
Strictly speaking I cannot see how the conversion routine returns OK and
has _not_ assigned a result. But the explicit assignment won't harm
either, and matches the fallback when the conversion fails (detectibly).
Which means that runtime behaviour won't change.
Gerhard Sittig [Fri, 9 Feb 2018 18:09:27 +0000 (19:09 +0100)]
lascar-el-usb: fix potential NULL dereference and memory leak
Check for successful allocation of multiple memory ranges, and release
partial allocations in the error path when one of them failed. This
fixes a potential memory leak, as well as avoids NULL dereferences.
Gerhard Sittig [Fri, 9 Feb 2018 17:50:53 +0000 (18:50 +0100)]
gmc-mh-1x-2x: fix potential memory leak
The scan_2x_bd232() routine used to always prepare one spare context,
and filled it in when a device was found, just to allocate another one
and continue scanning.
Free the last allocated context unconditionally, as it was allocated
unconditionally, and never used.
Gerhard Sittig [Thu, 8 Feb 2018 21:18:02 +0000 (22:18 +0100)]
session_driver: avoid division by zero, catch API violation
Avoid a division by zero, by not using a zero unitsize in a modulo
operation. As a byproduct, avoid processing and counting input that
neither has analog nor logic data. This should never have happened,
but the change now catches the error if invalid input is seen.
Gerhard Sittig [Thu, 8 Feb 2018 21:11:58 +0000 (22:11 +0100)]
session: fixup access to uninitialized memory
The sr_packet_copy() routine could have written to an arbitrary memory
location. Make sure to allocate the space before writing to it, and
check for successful allocation before accessing the memory.
It's assumed that this error never took effect, as the routine appears
to be unused.
Philipp Marek [Wed, 20 Dec 2017 15:10:59 +0000 (16:10 +0100)]
hantek-dso: dso2250: Fix capture runaway, only do the requested number of frames.
After the first capture ->num_frames never got to be _equal_
to ->limit_frames; fixed by resetting to zero in dev_acquisition_stop(),
and protected against similar problems in the future by switching to
greater-or-equal instead.
[Note: This patch is basically a squashed version of the initial driver
commits by Andreas Zschunke <redacted>, two fixes by
Andrej Valek <redacted>, and various coding style / cosmetic
fixes by Uwe Hermann <redacted> to make the driver a lot more
consistent with the rest of the libsigrok code-base.]
Stefan Brüns [Mon, 11 Dec 2017 03:17:26 +0000 (04:17 +0100)]
rigol-ds: Fix crash when fetching logic channels
When refactoring the code, some places where sr_scpi_send was replaced
by rigol_ds_config_set the first argument was not changed from sdi->conn
to sdi. Fix the remaining ones.
Due to how the sysclk-lwla driver does up to 3 open/close operations in
one dev_open() API callback we cannot rely on the sr_dev_open() and
sr_dev_close() wrappers setting the sdi->status variable in this case.
Gerhard Sittig [Mon, 13 Mar 2017 12:17:05 +0000 (13:17 +0100)]
input/vcd: fixup VCD timestamp to sigrok samplenum mapping
When processing of large VCD input files was spread across multiple
parse_contents() invocations, the resulting sigrok stream of sample data
had gaps in them and total timing was off. For instance 74ms of input
data were interpreted as spanning some 600ms or 300ms, depending on the
number of channels in the input stream.
Move the "previous timestamp" variable to the input module context. This
eliminates the inappropriate gaps and fixes the translation of VCD file
timestamps to sigrok sample numbers.
Stefan Brüns [Sun, 29 Oct 2017 19:57:11 +0000 (20:57 +0100)]
cleanup udev part of README.devices, reflect split rules
Remove vague statements from the README. On all current distributions,
the udev paths are identical, anyone deliberately deviating from the
defaults should be able to handle it by themselves.
Rules in /etc/udev/rules.d/ should only be used for customization, or
for locally built packages.
Stefan Brüns [Sun, 29 Oct 2017 19:03:53 +0000 (20:03 +0100)]
contrib: Split device access policy from the device database
Split the distribution independent database from the access policy rules.
This avoids warnings due to granting permissions to the commonly unknown
plugdev group, and allows simple overrides of the used access policy.
Stefan Brüns [Sun, 29 Oct 2017 17:35:06 +0000 (18:35 +0100)]
contrib: rename udev rules for correct rule ordering on systemd systems
The "uaccess" tag has to be added before the "seat" rule is evaluated.
The upstream default for the seat rule is "71-seat.rules", so use
60-libsigrok.rules for appropriate lexicographical sorting.
Also use a dash instead of underscore, the latter is commonly used as a
replacement character of unsafe characters in autogenerated identifiers.
Frank Stettner [Thu, 2 Nov 2017 17:04:59 +0000 (18:04 +0100)]
drivers: Fix locale dependent string to float conversion
Some drivers used locale dependent functions for converting strings
to float/double values. These functions fail when the decimal mark
is a "," in the locale settings but the string contains a ".".
Soeren Apel [Wed, 11 Oct 2017 16:14:56 +0000 (18:14 +0200)]
demo: Properly handle low samplerates
A "low samplerate" in this case means anything where
samples_todo is less than SAMPLES_PER_FRAME. This case
wasn't handled properly before, resulting in wrong
amounts of data being sent out.