sysfsutils/0002-Fix-compiler-complaint-about-string-truncation.patch
Lee Duncan 101c9a4968 Accepting request 817114 from home:lee_duncan:branches:Base:System
- fixes build issus on 64-bit ppc and s390
- Added a patch to bring sysfsutils up to latest upstream, which
  now is in place:
  * sysfsutils-latest-changes.diff.gz
- Added patches which have been submitted upstream but not yet
  merged:
  * 0001-Fix-compiler-complain-about-multiple-defs-of-my_stdo.patch
  * 0002-Fix-compiler-complaint-about-string-truncation.patch
  * 0003-Fix-more-string-issues-for-gcc-10.patch
  And removing a patch that's subsumed by the above patches:
  * sysfsutils-fix-compiler-issues.patch
  Lastly, replaced the hand-rolled sysfsutils-2.1.0.tar.gz with
  upstream archive file sysfsutils-sysfsutils-2_1_0.tar.gz,
  though the contents of the two are the same.

OBS-URL: https://build.opensuse.org/request/show/817114
OBS-URL: https://build.opensuse.org/package/show/Base:System/sysfsutils?expand=0&rev=18
2020-06-26 16:02:18 +00:00

91 lines
2.2 KiB
Diff

From 904296fbead9abe3369c3e455cd5cbf8c03419eb Mon Sep 17 00:00:00 2001
From: Lee Duncan <lduncan@suse.com>
Date: Wed, 24 Jun 2020 11:09:30 -0700
Subject: [PATCH 2/6] Fix compiler complaint about string truncation.
The compiler didn't like having to my_strncat()s defined,
so define it in one place, and refer to it elsewhere.
The string copying in this is still kind of crazy, but
it seems to work, and if the compiler can be happy,
so can I.
---
cmd/systool.c | 12 +-----------
lib/sysfs.h | 12 +-----------
lib/sysfs_utils.c | 16 ++++++++++++++++
3 files changed, 18 insertions(+), 22 deletions(-)
diff --git a/cmd/systool.c b/cmd/systool.c
index e273e6bf92ec..45ed36db1d54 100644
--- a/cmd/systool.c
+++ b/cmd/systool.c
@@ -32,17 +32,7 @@
#include "libsysfs.h"
#include "names.h"
-inline void my_strncpy(char *to, const char *from, size_t max)
-{
- size_t i;
-
- for (i = 0; i < max && from[i] != '\0'; i++)
- to[i] = from[i];
- if (i < max)
- to[i] = '\0';
- else
- to[max-1] = '\0';
-}
+extern char *my_strncpy(char *to, const char *from, size_t max);
#define safestrcpy(to, from) my_strncpy(to, from, sizeof(to))
#define safestrcpymax(to, from, max) my_strncpy(to, from, max)
diff --git a/lib/sysfs.h b/lib/sysfs.h
index ec9ba36b6eed..481c1e9b7cf2 100644
--- a/lib/sysfs.h
+++ b/lib/sysfs.h
@@ -33,17 +33,7 @@
#include <fcntl.h>
#include <errno.h>
-inline void my_strncpy(char *to, const char *from, size_t max)
-{
- size_t i;
-
- for (i = 0; i < max && from[i] != '\0'; i++)
- to[i] = from[i];
- if (i < max)
- to[i] = '\0';
- else
- to[max-1] = '\0';
-}
+extern char *my_strncpy(char *to, const char *from, size_t max);
#define safestrcpy(to, from) my_strncpy(to, from, sizeof(to))
#define safestrcpymax(to, from, max) my_strncpy(to, from, max)
diff --git a/lib/sysfs_utils.c b/lib/sysfs_utils.c
index 9ca207c7f1f0..43df36fb972c 100644
--- a/lib/sysfs_utils.c
+++ b/lib/sysfs_utils.c
@@ -305,3 +305,19 @@ int sysfs_path_is_file(const char *path)
return 1;
}
+
+/**
+ * my_strncpy -- a safe strncpy
+ */
+char *my_strncpy(char *to, const char *from, size_t max)
+{
+ size_t i;
+
+ for (i = 0; i < max && from[i] != '\0'; i++)
+ to[i] = from[i];
+ if (i < max)
+ to[i] = '\0';
+ else
+ to[max-1] = '\0';
+ return to;
+}
--
2.26.2