@@ -299,6 +299,7 @@ IdentifySystem(void)
299
299
char xpos [MAXFNAMELEN ];
300
300
XLogRecPtr logptr ;
301
301
char * dbname = NULL ;
302
+ Size len ;
302
303
303
304
/*
304
305
* Reply with a result set with one row, four columns. First col is system
@@ -380,21 +381,32 @@ IdentifySystem(void)
380
381
/* Send a DataRow message */
381
382
pq_beginmessage (& buf , 'D' );
382
383
pq_sendint (& buf , 4 , 2 ); /* # of columns */
383
- pq_sendint (& buf , strlen (sysid ), 4 ); /* col1 len */
384
- pq_sendbytes (& buf , (char * ) & sysid , strlen (sysid ));
385
- pq_sendint (& buf , strlen (tli ), 4 ); /* col2 len */
386
- pq_sendbytes (& buf , (char * ) tli , strlen (tli ));
387
- pq_sendint (& buf , strlen (xpos ), 4 ); /* col3 len */
388
- pq_sendbytes (& buf , (char * ) xpos , strlen (xpos ));
389
- /* send NULL if not connected to a database */
384
+
385
+ /* column 1: system identifier */
386
+ len = strlen (sysid );
387
+ pq_sendint (& buf , len , 4 );
388
+ pq_sendbytes (& buf , (char * ) & sysid , len );
389
+
390
+ /* column 2: timeline */
391
+ len = strlen (tli );
392
+ pq_sendint (& buf , len , 4 );
393
+ pq_sendbytes (& buf , (char * ) tli , len );
394
+
395
+ /* column 3: xlog position */
396
+ len = strlen (xpos );
397
+ pq_sendint (& buf , len , 4 );
398
+ pq_sendbytes (& buf , (char * ) xpos , len );
399
+
400
+ /* column 4: database name, or NULL if none */
390
401
if (dbname )
391
402
{
392
- pq_sendint (& buf , strlen (dbname ), 4 ); /* col4 len */
393
- pq_sendbytes (& buf , (char * ) dbname , strlen (dbname ));
403
+ len = strlen (dbname );
404
+ pq_sendint (& buf , len , 4 );
405
+ pq_sendbytes (& buf , (char * ) dbname , len );
394
406
}
395
407
else
396
408
{
397
- pq_sendint (& buf , -1 , 4 ); /* col4 len, NULL */
409
+ pq_sendint (& buf , -1 , 4 );
398
410
}
399
411
400
412
pq_endmessage (& buf );
@@ -413,6 +425,7 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
413
425
int fd ;
414
426
off_t histfilelen ;
415
427
off_t bytesleft ;
428
+ Size len ;
416
429
417
430
/*
418
431
* Reply with a result set with one row, and two columns. The first col is
@@ -448,8 +461,9 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
448
461
/* Send a DataRow message */
449
462
pq_beginmessage (& buf , 'D' );
450
463
pq_sendint (& buf , 2 , 2 ); /* # of columns */
451
- pq_sendint (& buf , strlen (histfname ), 4 ); /* col1 len */
452
- pq_sendbytes (& buf , histfname , strlen (histfname ));
464
+ len = strlen (histfname );
465
+ pq_sendint (& buf , len , 4 ); /* col1 len */
466
+ pq_sendbytes (& buf , histfname , len );
453
467
454
468
fd = OpenTransientFile (path , O_RDONLY | PG_BINARY , 0666 );
455
469
if (fd < 0 )
@@ -675,6 +689,7 @@ StartReplication(StartReplicationCmd *cmd)
675
689
{
676
690
char tli_str [11 ];
677
691
char startpos_str [8 + 1 + 8 + 1 ];
692
+ Size len ;
678
693
679
694
snprintf (tli_str , sizeof (tli_str ), "%u" , sendTimeLineNextTLI );
680
695
snprintf (startpos_str , sizeof (startpos_str ), "%X/%X" ,
@@ -711,11 +726,13 @@ StartReplication(StartReplicationCmd *cmd)
711
726
pq_beginmessage (& buf , 'D' );
712
727
pq_sendint (& buf , 2 , 2 ); /* number of columns */
713
728
714
- pq_sendint (& buf , strlen (tli_str ), 4 ); /* length */
715
- pq_sendbytes (& buf , tli_str , strlen (tli_str ));
729
+ len = strlen (tli_str );
730
+ pq_sendint (& buf , len , 4 ); /* length */
731
+ pq_sendbytes (& buf , tli_str , len );
716
732
717
- pq_sendint (& buf , strlen (startpos_str ), 4 ); /* length */
718
- pq_sendbytes (& buf , startpos_str , strlen (startpos_str ));
733
+ len = strlen (startpos_str );
734
+ pq_sendint (& buf , len , 4 ); /* length */
735
+ pq_sendbytes (& buf , startpos_str , len );
719
736
720
737
pq_endmessage (& buf );
721
738
}
@@ -763,10 +780,10 @@ logical_read_xlog_page(XLogReaderState *state, XLogRecPtr targetPagePtr, int req
763
780
static void
764
781
CreateReplicationSlot (CreateReplicationSlotCmd * cmd )
765
782
{
766
- const char * slot_name ;
767
783
const char * snapshot_name = NULL ;
768
784
char xpos [MAXFNAMELEN ];
769
785
StringInfoData buf ;
786
+ Size len ;
770
787
771
788
Assert (!MyReplicationSlot );
772
789
@@ -792,14 +809,11 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
792
809
793
810
initStringInfo (& output_message );
794
811
795
- slot_name = NameStr (MyReplicationSlot -> data .name );
796
-
797
812
if (cmd -> kind == REPLICATION_KIND_LOGICAL )
798
813
{
799
814
LogicalDecodingContext * ctx ;
800
815
801
- ctx = CreateInitDecodingContext (
802
- cmd -> plugin , NIL ,
816
+ ctx = CreateInitDecodingContext (cmd -> plugin , NIL ,
803
817
logical_read_xlog_page ,
804
818
WalSndPrepareWrite , WalSndWriteData );
805
819
@@ -827,7 +841,6 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
827
841
ReplicationSlotPersist ();
828
842
}
829
843
830
- slot_name = NameStr (MyReplicationSlot -> data .name );
831
844
snprintf (xpos , sizeof (xpos ), "%X/%X" ,
832
845
(uint32 ) (MyReplicationSlot -> data .confirmed_flush >> 32 ),
833
846
(uint32 ) MyReplicationSlot -> data .confirmed_flush );
@@ -878,30 +891,34 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
878
891
pq_sendint (& buf , 4 , 2 ); /* # of columns */
879
892
880
893
/* slot_name */
881
- pq_sendint (& buf , strlen (slot_name ), 4 ); /* col1 len */
882
- pq_sendbytes (& buf , slot_name , strlen (slot_name ));
894
+ len = strlen (NameStr (MyReplicationSlot -> data .name ));
895
+ pq_sendint (& buf , len , 4 ); /* col1 len */
896
+ pq_sendbytes (& buf , NameStr (MyReplicationSlot -> data .name ), len );
883
897
884
898
/* consistent wal location */
885
- pq_sendint (& buf , strlen (xpos ), 4 ); /* col2 len */
886
- pq_sendbytes (& buf , xpos , strlen (xpos ));
899
+ len = strlen (xpos );
900
+ pq_sendint (& buf , len , 4 );
901
+ pq_sendbytes (& buf , xpos , len );
887
902
888
- /* snapshot name */
903
+ /* snapshot name, or NULL if none */
889
904
if (snapshot_name != NULL )
890
905
{
891
- pq_sendint (& buf , strlen (snapshot_name ), 4 ); /* col3 len */
892
- pq_sendbytes (& buf , snapshot_name , strlen (snapshot_name ));
906
+ len = strlen (snapshot_name );
907
+ pq_sendint (& buf , len , 4 );
908
+ pq_sendbytes (& buf , snapshot_name , len );
893
909
}
894
910
else
895
- pq_sendint (& buf , -1 , 4 ); /* col3 len, NULL */
911
+ pq_sendint (& buf , -1 , 4 );
896
912
897
- /* plugin */
913
+ /* plugin, or NULL if none */
898
914
if (cmd -> plugin != NULL )
899
915
{
900
- pq_sendint (& buf , strlen (cmd -> plugin ), 4 ); /* col4 len */
901
- pq_sendbytes (& buf , cmd -> plugin , strlen (cmd -> plugin ));
916
+ len = strlen (cmd -> plugin );
917
+ pq_sendint (& buf , len , 4 );
918
+ pq_sendbytes (& buf , cmd -> plugin , len );
902
919
}
903
920
else
904
- pq_sendint (& buf , -1 , 4 ); /* col4 len, NULL */
921
+ pq_sendint (& buf , -1 , 4 );
905
922
906
923
pq_endmessage (& buf );
907
924
0 commit comments