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.
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.
The srzip output module dropped support for the "filename" option in
commit 37875f7506 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.
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",
^
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,
^
Check pointers' validity before dereferencing them. Release partially
allocated memory in an error path. Remove an assignment which never took
effect.
This was reported by clang's scan-build.
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.
This was reported by clang's scan-build.
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.
This was reported by clang's scan-build.
Remove an assignment that won't take effect. Check pointers' validity
before dereferencing. Fix a memory leak.
This was reported by clang's scan-build.
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.
This was reported by clang's scan-build.
Silence warnings about assigned values that never get used, potential
NULL deference, and potential memory leaks.
This was reported by clang's scan-build.
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.
This was reported by clang's scan-build.
Stick with the prepared but unfinished "limit msec" code path, but
silence the warning about an unused variable value.
This was reported by clang's scan-build.
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.
This was reported by clang's scan-build.
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.
This was reported by clang's scan-build.
The 'opc' variable was only conditionally assigned to (depends on
successful SCPI communication). Ensure there always is a known value.
This was reported by clang's scan-build.
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.