Skip to content

Commit 3b03e6c

Browse files
committed
Fixing the low-hanging-fruit warnings.
1 parent 83a614a commit 3b03e6c

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

compare_argument.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "compare_argument.h"
22

33
#include <stdlib.h>
4+
#include <stddef.h>
45
#include <string.h>
56
#include <stdio.h>
67

@@ -103,7 +104,7 @@ enum option_comparison_result compare_argument(const char option_name_char, cons
103104
if(out_argv)
104105
*out_argv = argv;
105106
if(out_args_consumed)
106-
*out_args_consumed = argv - orig_argv;
107+
*out_args_consumed = (unsigned int)(ptrdiff_t)(argv - orig_argv);
107108

108109
return result;
109110
}

main.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct argblock {
2121
CFStringRef pasteboardID;
2222
const char *pasteboardID_cstr;
2323

24-
UInt32 itemIndex;
24+
CFIndex itemIndex;
2525

2626
CFStringRef type; //UTI
2727

@@ -78,7 +78,7 @@ int main(int argc, const char **argv) {
7878
initpb(&pb);
7979

8080
while((--argc) && (pb.flags.phase != subcommand_options)) {
81-
if(retval = parsearg(*++argv, &pb))
81+
if((retval = parsearg(*++argv, &pb)))
8282
break;
8383
}
8484
//The subcommand gets our leftover arguments.
@@ -135,7 +135,8 @@ int main(int argc, const char **argv) {
135135

136136
Boolean testarg(const char *a, const char *b, const char **param) {
137137
while((*a) && (*a == *b) && (*b != '=')) {
138-
++a, ++b;
138+
++a;
139+
++b;
139140
}
140141

141142
if(param) *param = (*a == '=') ? &a[1] : NULL;
@@ -293,7 +294,7 @@ static const char *make_cstr_for_CFStr(CFStringRef in, CFStringEncoding encoding
293294
CFStringGetBytes(in, IDrange, encoding, /*lossByte*/ 0U, /*isExternalRepresentation*/ false, /*buffer*/ NULL, /*maxBufLen*/ 0, &numBytes);
294295
char *buf = pb_allocate(numBytes + 1U);
295296
if(buf) {
296-
CFIndex numChars = CFStringGetBytes(in, IDrange, encoding, /*lossByte*/ 0U, /*isExternalRepresentation*/ false, (unsigned char *)buf, /*maxBufLen*/ numBytes, &numBytes);
297+
CFIndex numChars __attribute__((unused)) = CFStringGetBytes(in, IDrange, encoding, /*lossByte*/ 0U, /*isExternalRepresentation*/ false, (unsigned char *)buf, /*maxBufLen*/ numBytes, &numBytes);
297298
buf[numBytes] = 0;
298299
}
299300
result = buf;
@@ -315,8 +316,7 @@ static PasteboardItemID getRandomPasteboardItemID(void) {
315316

316317
PasteboardItemID item;
317318

318-
srandom(time(NULL));
319-
item = (PasteboardItemID)random();
319+
item = (PasteboardItemID)(unsigned long)arc4random();
320320

321321
//An item ID of 0 is illegal. Make sure it doesn't happen.
322322
if(item == 0)
@@ -462,7 +462,7 @@ int copy(struct argblock *pbptr) {
462462
free(buf);
463463

464464
if(err != noErr) {
465-
fprintf(stderr, "%s copy: could not copy to pasteboard %s because PasteboardPutItemFlavor returned %li (%s)\n", argv0, make_pasteboardID_cstr(pbptr), err);
465+
fprintf(stderr, "%s copy: could not copy to pasteboard %s because PasteboardPutItemFlavor returned %li (%s)\n", argv0, make_pasteboardID_cstr(pbptr), (long)err, GetMacOSStatusCommentString(err));
466466
retval = 2;
467467
}
468468

@@ -514,9 +514,9 @@ int paste_one(struct argblock *pbptr) {
514514

515515
if(err != noErr) {
516516
if(err == badPasteboardFlavorErr)
517-
fprintf(stderr, "%s: could not paste item %u of pasteboard \"%s\": it does not exist in flavor type \"%s\".\n", argv0, pbptr->itemIndex, make_pasteboardID_cstr(pbptr), make_cstr_for_CFStr(pbptr->type, kCFStringEncodingUTF8));
517+
fprintf(stderr, "%s: could not paste item %lu of pasteboard \"%s\": it does not exist in flavor type \"%s\".\n", argv0, (unsigned long)pbptr->itemIndex, make_pasteboardID_cstr(pbptr), make_cstr_for_CFStr(pbptr->type, kCFStringEncodingUTF8));
518518
else
519-
fprintf(stderr, "%s: could not paste item %u of pasteboard \"%s\": PasteboardCopyItemFlavorData (for flavor type \"%s\") returned error %li\n", argv0, pbptr->itemIndex, make_pasteboardID_cstr(pbptr), make_cstr_for_CFStr(pbptr->type, kCFStringEncodingUTF8), (long)err, GetMacOSStatusCommentString(err));
519+
fprintf(stderr, "%s: could not paste item %lu of pasteboard \"%s\": PasteboardCopyItemFlavorData (for flavor type \"%s\") returned error %li (%s)\n", argv0, (unsigned long)pbptr->itemIndex, make_pasteboardID_cstr(pbptr), make_cstr_for_CFStr(pbptr->type, kCFStringEncodingUTF8), (long)err, GetMacOSStatusCommentString(err));
520520
retval = 2;
521521
} else {
522522
write(pbptr->out_fd, CFDataGetBytePtr(data), CFDataGetLength(data));
@@ -528,7 +528,6 @@ int paste_one(struct argblock *pbptr) {
528528
return retval;
529529
}
530530
int paste(struct argblock *pbptr) {
531-
int retval = 0;
532531
ItemCount numItems = 0U;
533532
OSStatus err = PasteboardGetItemCount(pbptr->pasteboard, &numItems);
534533
if(err != noErr) {
@@ -541,11 +540,10 @@ int paste(struct argblock *pbptr) {
541540
pbptr->out_fd = STDOUT_FILENO;
542541
if(!(pbptr->type))
543542
pbptr->type = CFRetain(kUTTypeUTF8PlainText);
544-
if((pbptr->itemIndex) == 0U)
545-
pbptr->itemIndex = 1U;
543+
if((pbptr->itemIndex) == 0UL)
544+
pbptr->itemIndex = 1UL;
546545
return paste_one(pbptr);
547546
} else {
548-
UInt32 index = 1U;
549547
struct argblock these_args = *pbptr;
550548
struct argblock *these_args_ptr = &these_args;
551549

@@ -557,7 +555,7 @@ int paste(struct argblock *pbptr) {
557555
//If two option values after the paste command collide (e.g. two filenames), paste_one is invoked with the first value, and then we will begin a new set of arguments with the second value.
558556
//If we get all three option values (filename, type, index), paste_one is invoked, and then we begin a new set of arguments.
559557
Boolean has_encountered_index = false;
560-
UInt32 numericValue;
558+
CFIndex numericValue;
561559

562560
while(*(pbptr->argv) && !(pbptr->filename && type_cstr && index_cstr)) {
563561
const char *option_arg = NULL;
@@ -578,10 +576,10 @@ int paste(struct argblock *pbptr) {
578576
index_cstr = option_arg;
579577
numericValue = strtoul(index_cstr, NULL, 10);
580578
if(numericValue == 0U) {
581-
fprintf(stderr, "%s: Invalid index %u\n", argv0, numericValue);
579+
fprintf(stderr, "%s: Invalid index %lu\n", argv0, numericValue);
582580
return 1;
583581
} else if(numericValue > numItems) {
584-
fprintf(stderr, "%s: Index %u exceeds number of items %u\n", argv0, numericValue, numItems);
582+
fprintf(stderr, "%s: Index %lu exceeds number of items %lu\n", argv0, (unsigned long)numericValue, numItems);
585583
return 1;
586584
} else {
587585
if(has_encountered_index)

0 commit comments

Comments
 (0)