Skip to content

Commit

Permalink
iio-monitor: Now the c90 warnings are gone, fix real warnings
Browse files Browse the repository at this point in the history
older versions of CDK need things to be casted to it's own
type, so check for that and do it.

Some libraries flag asprintf as must check return value, since it does a
malloc() and can fail, so do that.

Signed-off-by: Robin Getz <[email protected]>
  • Loading branch information
rgetz committed Apr 27, 2020
1 parent a330cc1 commit 88b946f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
13 changes: 13 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,26 @@ if (PTHREAD_LIBRARIES
AND CDK_LIBRARY
)
find_path(LIBCKD_INCLUDE_DIR cdk.h PATH_SUFFIXES cdk)

set(TEMP ${CMAKE_REQUIRED_LIBRARIES})
set(TEMP1 ${CMAKE_REQUIRED_INCLUDES})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CURSES_LIBRARY} ${CDK_LIBRARY})
list(APPEND CMAKE_REQUIRED_INCLUDES ${LIBCKD_INCLUDE_DIR})
check_symbol_exists(CDK_CSTRING2 "cdk.h" HAS_CDK_CSTRING2)
set(CMAKE_REQUIRED_LIBRARIES ${TEMP})
set(CMAKE_REQUIRED_INCLUDES ${TEMP1})
endif()

if(HAS_CDK_CSTRING2)
include_directories(${LIBCKD_INCLUDE_DIR})
project(iio-monitor C)
add_executable(iio-monitor iio-monitor.c)
target_link_libraries(
iio-monitor iio ${PTHREAD_LIBRARIES} ${CURSES_LIBRARY} ${CDK_LIBRARY}
)
set(IIO_TESTS_TARGETS ${IIO_TESTS_TARGETS} iio-monitor)
else()
message(STATUS "Curses Development Kit (CDK) missing or too old, skipping iio-monitor")
endif ()

set_target_properties(
Expand Down
17 changes: 12 additions & 5 deletions examples/iio-monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static struct {
{ "power", "W" },
{ "temp", "°C" },
{ "voltage", "V" },
{ 0, },
{ NULL, NULL },
};

static const char *id_to_unit(const char *id)
Expand Down Expand Up @@ -265,18 +265,25 @@ static struct iio_context *show_contexts_screen(void)
}

for (i = 0; i < num_contexts; i++) {
asprintf(&items[i], "</%d>%s<!%d> </%d>[%s]<!%d>", YELLOW,
ret = asprintf(&items[i], "</%d>%s<!%d> </%d>[%s]<!%d>", YELLOW,
iio_context_info_get_description(info[i]),
YELLOW, BLUE,
iio_context_info_get_uri(info[i]),
BLUE);
if (ret < 0) {
fprintf(stderr, "asprintf failed, out of memory?\n");
break;
}
}
if (ret < 0) {
break;
}

items[i] = "Enter location";

list = newCDKScroll(screen, LEFT, TOP, RIGHT, 0, 0,
"\n Select a IIO context to use:\n",
items, num_contexts + 1, TRUE,
(CDK_CSTRING2) items, num_contexts + 1, TRUE,
A_BOLD | A_REVERSE, TRUE, FALSE);

drawCDKScroll(list, TRUE);
Expand All @@ -298,7 +305,7 @@ static struct iio_context *show_contexts_screen(void)
ctx = iio_create_context_from_uri(uri);
if (ctx == NULL) {
char *msg[] = { "</16>Failed to create IIO context.<!16>" };
popupLabel(screen, msg, 1);
popupLabel(screen, (CDK_CSTRING2)msg, 1);
}

if (free_uri)
Expand Down Expand Up @@ -364,7 +371,7 @@ static void show_main_screen(struct iio_context *ctx)
boxWindow(right, 0);
list = newCDKScroll(screen, LEFT, TOP, RIGHT, 0, 0,
"\n List of available IIO devices:\n",
dev_names, nb_devices, FALSE,
(CDK_CSTRING2) dev_names, nb_devices, FALSE,
A_BOLD | A_REVERSE, TRUE, FALSE);

drawCDKScroll(list, TRUE);
Expand Down

0 comments on commit 88b946f

Please sign in to comment.