Skip to content

Commit

Permalink
Feature: Fix compiler warnings, Refactor and Cleanup (#2817)
Browse files Browse the repository at this point in the history
* Feature: Fix compiler warnings, Refactor and Cleanup

Add fixes for many compiler errors
Mostly this is just adding `__attribute__((unused))`
Fix some of the formatting broken by clang-format
Replace many `sprintf` with `snprintf`
Rename `wait` to `short_wait` to avoid name conflicts in `UdpEventsTest`
Remove unused test functions for labview

* Remove line instead of commenting it out
  • Loading branch information
WhoBrokeTheBuild authored Nov 8, 2024
1 parent a71ebad commit 80eced4
Show file tree
Hide file tree
Showing 29 changed files with 503 additions and 419 deletions.
2 changes: 1 addition & 1 deletion camshr/QueryHighwayType.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static char *ShowType(int type);
int QueryHighwayType(char *serial_hwy_driver)
{
char line[80];
char tmpVendor[9], tmpModel[17], tmpRev[5];
char tmpVendor[9], tmpModel[17], tmpRev[6];
int foundHost, foundVendor, highwayType = TYPE_UNKNOWN, host_adapter, scsi_id,
tmpHost, tmpId;
int status = SUCCESS; // optimistic
Expand Down
4 changes: 2 additions & 2 deletions camshr/RSD.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RSD.h -- request sense data
#ifndef __RSD_H
#define __RSD_H
#pragma pack(1)
#pragma pack(push, 1)
// for Linux on x86
// NB! order of members is different from original
// to get data to pack into same size memory, ie
Expand Down Expand Up @@ -65,5 +65,5 @@ typedef struct

__u32 stacnt;
} RequestSenseData;
#pragma pack(4)
#pragma pack(pop)
#endif
2 changes: 1 addition & 1 deletion camshr/cam_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ static int CamAssign(char *Name, CamKey *Key)
if (strchr(Name, ':'))
{ // physical names contain a ':'
str2upcase(Name);
sscanf(Name, "GK%1s%1d%2d:N%d", &ha, &id, &crate, &slot);
sscanf(Name, "GK%c%1d%2d:N%d", &ha, &id, &crate, &slot);
Key->scsi_port = ha;
Key->scsi_address = id;
Key->crate = crate;
Expand Down
2 changes: 1 addition & 1 deletion camshr/check_sema4.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ union semun {
int check_sema4()
{
int count;
union semun u;
union semun u = {};

extern int semid;

Expand Down
6 changes: 3 additions & 3 deletions camshr/scsi_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int SGSetMAXBUF(int scsiDevice, int new)
int old = -1;
char *bufptr;
int fd = -1;
if (scsiDevice >= 0 || scsiDevice <= 9)
if (scsiDevice >= 0 && scsiDevice <= 9)
{
old = MAXBUF[scsiDevice];
if (new >= MIN_MAXBUF)
Expand All @@ -112,7 +112,7 @@ int SGSetMAXBUF(int scsiDevice, int new)

int SGGetMAXBUF(int scsiDevice)
{
if (scsiDevice >= 0 || scsiDevice <= 9)
if (scsiDevice >= 0 && scsiDevice <= 9)
{
char *bufptr;
OpenScsi(scsiDevice, &bufptr);
Expand All @@ -127,7 +127,7 @@ static int OpenScsi(int scsiDevice, char **buff_out)
char *buff = 0;
static char *BUFFS[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int fd = -1;
if (scsiDevice >= 0 || scsiDevice <= 9)
if (scsiDevice >= 0 && scsiDevice <= 9)
{
if (FDS[scsiDevice] >= 0)
{
Expand Down
5 changes: 2 additions & 3 deletions examples/demoadc/DemoAdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define PI 3.14159265358
static int totSamples = 65536;
static double frequency;
static int pts;
static int confOk;
// Return 0 if succesful, -1 if any argument is not correct
int initialize(char *name, int clockFreq, int postTriggerSamples)
Expand Down Expand Up @@ -89,7 +88,7 @@ int initialize(char *name, int clockFreq, int postTriggerSamples)
return 1;
}

int acquire(char *name, short *c1, short *c2, short *c3, short *c4)
int acquire(char *name __attribute__((unused)), short *c1, short *c2, short *c3, short *c4)
{
int i;
printf("ACQUIRE\n");
Expand All @@ -109,7 +108,7 @@ int acquire(char *name, short *c1, short *c2, short *c3, short *c4)
static long currSamples;
static double currPeriod;
static double trigger;
int initializeStream(char *name, float clockFreq, float trigTime)
int initializeStream(char *name __attribute__((unused)), float clockFreq, float trigTime)
{
printf("INITIALIZE STREAM: %s, %f, %f\n", name, clockFreq, trigTime);
currPeriod = 1./clockFreq;
Expand Down
32 changes: 13 additions & 19 deletions include/dtypedef.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
/*
* atomic data types 0 - 37, 51-55
*/
DEFINE(MISSING, 0) /* no data */
DEFINE(V_deprecated, 1) /* aligned bit string */
DEFINE(BU, 2) /* byte (unsigned); 8-bit unsigned quantity */
DEFINE(WU, 3) /* word (unsigned); 16-bit unsigned quantity */
DEFINE(LU, 4) /* longword (unsigned); 32-bit unsigned quantity */
DEFINE(QU, 5) /* quadword (unsigned); 64-bit unsigned quantity */
DEFINE(B, 6) /* byte integer (signed); 8-bit signed 2's-complement integer */
DEFINE(W, 7) /* word integer (signed); 16-bit signed 2's-complement integer */
DEFINE(L,
8) /* longword integer (signed); 32-bit signed 2's-complement integer */
DEFINE(Q,
9) /* quadword integer (signed); 64-bit signed 2's-complement integer */
DEFINE(MISSING, 0) /* no data */
DEFINE(V_deprecated, 1) /* aligned bit string */
DEFINE(BU, 2) /* byte (unsigned); 8-bit unsigned quantity */
DEFINE(WU, 3) /* word (unsigned); 16-bit unsigned quantity */
DEFINE(LU, 4) /* longword (unsigned); 32-bit unsigned quantity */
DEFINE(QU, 5) /* quadword (unsigned); 64-bit unsigned quantity */
DEFINE(B, 6) /* byte integer (signed); 8-bit signed 2's-complement integer */
DEFINE(W, 7) /* word integer (signed); 16-bit signed 2's-complement integer */
DEFINE(L, 8) /* longword integer (signed); 32-bit signed 2's-complement integer */
DEFINE(Q, 9) /* quadword integer (signed); 64-bit signed 2's-complement integer */
DEFINE(F, 10) /* F_floating; 32-bit single-precision floating point */
DEFINE(D, 11) /* D_floating; 64-bit double-precision floating point */
DEFINE(FC, 12) /* F_floating complex */
DEFINE(DC, 13) /* D_floating complex */
DEFINE(T, 14) /* character string; a single 8-bit character or a sequence of
characters */
DEFINE(T, 14) /* character string; a single 8-bit character or a sequence of characters */
DEFINE(NU_deprecated, 15) /* numeric string) unsigned */
DEFINE(NL_deprecated, 16) /* numeric string) left separate sign */
DEFINE(NLO_deprecated, 17) /* numeric string) left overpunched sign */
Expand All @@ -30,9 +27,7 @@ DEFINE(ZI_deprecated, 22) /* sequence of instructions */
DEFINE(ZEM_deprecated, 23) /* procedure entry mask */
DEFINE(DSC, 24) /* descriptor */
DEFINE(OU, 25) /* octaword (unsigned); 128-bit unsigned quantity */
DEFINE(
O,
26) /* octaword integer (signed); 128-bit signed 2's-complement integer */
DEFINE(O, 26) /* octaword integer (signed); 128-bit signed 2's-complement integer */
DEFINE(G, 27) /* G_floating; 64-bit double-precision floating point */
DEFINE(H, 28) /* H_floating; 128-bit quadruple-precision floating point */
DEFINE(GC, 29) /* G_floating complex */
Expand All @@ -42,8 +37,7 @@ DEFINE(BPV_deprecated, 32) /* bound procedure value */
DEFINE(BLV_deprecated, 33) /* bound label value */
DEFINE(VU_deprecated, 34) /* unaligned bit string */
DEFINE(ADT_deprecated, 35) /* absolute date and time */
DEFINE(VT_deprecated,
37) /* varying character string; 16-bit count) followed by a string */
DEFINE(VT_deprecated, 37) /* varying character string; 16-bit count) followed by a string */
/*
* 38 - 50 might have been used for RESERVED purposes
*/
Expand Down
15 changes: 5 additions & 10 deletions include/mdsdescrip.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,11 @@ typedef struct descriptor_d
typedef struct
{
unsigned __char_align__ : 3; /* reserved; must be zero */
unsigned __char_align__
binscale : 1; /* if set, scale is a power-of-two, otherwise, -ten */
unsigned __char_align__
redim : 1; /* if set, indicates the array can be redimensioned */
unsigned __char_align__
column : 1; /* if set, indicates column-major order (FORTRAN) */
unsigned __char_align__
coeff : 1; /* if set, indicates the multipliers block is present */
unsigned __char_align__
bounds : 1; /* if set, indicates the bounds block is present */
unsigned __char_align__ binscale : 1; /* if set, scale is a power-of-two, otherwise, -ten */
unsigned __char_align__ redim : 1; /* if set, indicates the array can be redimensioned */
unsigned __char_align__ column : 1; /* if set, indicates column-major order (FORTRAN) */
unsigned __char_align__ coeff : 1; /* if set, indicates the multipliers block is present */
unsigned __char_align__ bounds : 1; /* if set, indicates the bounds block is present */
} aflags_t; /* array flag bits */

typedef int8_t scale_t;
Expand Down
3 changes: 1 addition & 2 deletions mdslib/testing/mdslib_ctest.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ int main(int argc, char *argv[])
socket = MdsConnect("local://0");
TEST((socket != INVALID_SOCKET));
}
TEST(
MdsValue("TreeOpenNew('" TREE "'," SHOTS ")", &dsc, &null, &returnlength))
TEST(MdsValue("TreeOpenNew('" TREE "'," SHOTS ")", &dsc, &null, &returnlength))
TEST(MdsValue("{_=-1;TreeAddNode('A',_,'ANY');}", &dsc, &null, &returnlength))
TEST(MdsValue("TreeWrite('" TREE "'," SHOTS ")", &dsc, &null, &returnlength))
TEST(MdsValue("TreeClose('" TREE "'," SHOTS ")", &dsc, &null, &returnlength))
Expand Down
6 changes: 3 additions & 3 deletions mdsobjects/cpp/mdsdataobjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,7 @@ Data *Uint8Array::deserialize() { return (Data *)deserializeData(ptr); }
void Scope::show()
{
char expr[256];
std::sprintf(expr, "JavaShowWindow(%d, %d, %d, %d, %d)", idx, x, y, width,
std::snprintf(expr, sizeof(expr), "JavaShowWindow(%d, %d, %d, %d, %d)", idx, x, y, width,
height);
Data *ris = execute(expr);
deleteData(ris);
Expand All @@ -1900,15 +1900,15 @@ Scope::Scope(const char *name, int x, int y, int width, int height)
void Scope::plot(Data *x, Data *y, int row, int col, const char *color)
{
char expr[256];
std::sprintf(expr, "JavaReplaceSignal(%d, $1, $2, %d, %d, \"%s\")", idx, row,
std::snprintf(expr, sizeof(expr), "JavaReplaceSignal(%d, $1, $2, %d, %d, \"%s\")", idx, row,
col, color);
Data *ris = executeWithArgs(expr, 2, x, y);
deleteData(ris);
}
void Scope::oplot(Data *x, Data *y, int row, int col, const char *color)
{
char expr[256];
std::sprintf(expr, "JavaAddSignal(%d, $1, $2, %d, %d, \"%s\")", idx, row, col,
std::snprintf(expr, sizeof(expr), "JavaAddSignal(%d, $1, $2, %d, %d, \"%s\")", idx, row, col,
color);
Data *ris = executeWithArgs(expr, 2, x, y);
deleteData(ris);
Expand Down
6 changes: 3 additions & 3 deletions mdsobjects/cpp/mdsipobjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ void Connection::setDefault(char *path)
TreeNodeThinClient *Connection::getNode(char *path)
{
char expr[256];
sprintf(expr, "GETNCI(%s, \'NID_NUMBER\')", path);
snprintf(expr, sizeof(expr), "GETNCI(%s, \'NID_NUMBER\')", path);
AutoData<Data> nidData(get(expr));
if (!nidData)
throw MdsException("Cannot get remote nid in Connection::getNode");
Expand All @@ -690,7 +690,7 @@ void Connection::registerStreamListener(DataStreamListener *listener,
char *expr, char *tree, int shot)
{
char regExpr[64 + strlen(expr) + strlen(tree)];
sprintf(regExpr, "MdsObjectsCppShr->registerListener(\"%s\",\"%s\",val(%d))",
snprintf(regExpr, sizeof(regExpr), "MdsObjectsCppShr->registerListener(\"%s\",\"%s\",val(%d))",
expr, tree, shot);

AutoData<Data> idData(get(regExpr, NULL, 0));
Expand All @@ -710,7 +710,7 @@ void Connection::unregisterStreamListener(DataStreamListener *listener)
return;
int id = listenerIdV[idx];
char regExpr[64];
sprintf(regExpr, "MdsObjectsCppShr->unregisterListener(val(%d))", id);
snprintf(regExpr, sizeof(regExpr), "MdsObjectsCppShr->unregisterListener(val(%d))", id);
get(regExpr);
listenerV.erase(listenerV.begin() + idx);
listenerIdV.erase(listenerIdV.begin() + idx);
Expand Down
Loading

0 comments on commit 80eced4

Please sign in to comment.