@@ -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 )
@@ -674,6 +688,7 @@ StartReplication(StartReplicationCmd *cmd)
674
688
{
675
689
char tli_str [11 ];
676
690
char startpos_str [8 + 1 + 8 + 1 ];
691
+ Size len ;
677
692
678
693
snprintf (tli_str ,sizeof (tli_str ),"%u" ,sendTimeLineNextTLI );
679
694
snprintf (startpos_str ,sizeof (startpos_str ),"%X/%X" ,
@@ -710,11 +725,13 @@ StartReplication(StartReplicationCmd *cmd)
710
725
pq_beginmessage (& buf ,'D' );
711
726
pq_sendint (& buf ,2 ,2 );/* number of columns */
712
727
713
- pq_sendint (& buf ,strlen (tli_str ),4 );/* length */
714
- pq_sendbytes (& buf ,tli_str ,strlen (tli_str ));
728
+ len = strlen (tli_str );
729
+ pq_sendint (& buf ,len ,4 );/* length */
730
+ pq_sendbytes (& buf ,tli_str ,len );
715
731
716
- pq_sendint (& buf ,strlen (startpos_str ),4 );/* length */
717
- pq_sendbytes (& buf ,startpos_str ,strlen (startpos_str ));
732
+ len = strlen (startpos_str );
733
+ pq_sendint (& buf ,len ,4 );/* length */
734
+ pq_sendbytes (& buf ,startpos_str ,len );
718
735
719
736
pq_endmessage (& buf );
720
737
}
@@ -762,10 +779,10 @@ logical_read_xlog_page(XLogReaderState *state, XLogRecPtr targetPagePtr, int req
762
779
static void
763
780
CreateReplicationSlot (CreateReplicationSlotCmd * cmd )
764
781
{
765
- const char * slot_name ;
766
782
const char * snapshot_name = NULL ;
767
783
char xpos [MAXFNAMELEN ];
768
784
StringInfoData buf ;
785
+ Size len ;
769
786
770
787
Assert (!MyReplicationSlot );
771
788
@@ -791,14 +808,11 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
791
808
792
809
initStringInfo (& output_message );
793
810
794
- slot_name = NameStr (MyReplicationSlot -> data .name );
795
-
796
811
if (cmd -> kind == REPLICATION_KIND_LOGICAL )
797
812
{
798
813
LogicalDecodingContext * ctx ;
799
814
800
- ctx = CreateInitDecodingContext (
801
- cmd -> plugin ,NIL ,
815
+ ctx = CreateInitDecodingContext (cmd -> plugin ,NIL ,
802
816
logical_read_xlog_page ,
803
817
WalSndPrepareWrite ,WalSndWriteData );
804
818
@@ -834,7 +848,6 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
834
848
ReplicationSlotSave ();
835
849
}
836
850
837
- slot_name = NameStr (MyReplicationSlot -> data .name );
838
851
snprintf (xpos ,sizeof (xpos ),"%X/%X" ,
839
852
(uint32 ) (MyReplicationSlot -> data .confirmed_flush >>32 ),
840
853
(uint32 )MyReplicationSlot -> data .confirmed_flush );
@@ -885,30 +898,34 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
885
898
pq_sendint (& buf ,4 ,2 );/* # of columns */
886
899
887
900
/* slot_name */
888
- pq_sendint (& buf ,strlen (slot_name ),4 );/* col1 len */
889
- pq_sendbytes (& buf ,slot_name ,strlen (slot_name ));
901
+ len = strlen (NameStr (MyReplicationSlot -> data .name ));
902
+ pq_sendint (& buf ,len ,4 );/* col1 len */
903
+ pq_sendbytes (& buf ,NameStr (MyReplicationSlot -> data .name ),len );
890
904
891
905
/* consistent wal location */
892
- pq_sendint (& buf ,strlen (xpos ),4 );/* col2 len */
893
- pq_sendbytes (& buf ,xpos ,strlen (xpos ));
906
+ len = strlen (xpos );
907
+ pq_sendint (& buf ,len ,4 );
908
+ pq_sendbytes (& buf ,xpos ,len );
894
909
895
- /* snapshot name */
910
+ /* snapshot name, or NULL if none */
896
911
if (snapshot_name != NULL )
897
912
{
898
- pq_sendint (& buf ,strlen (snapshot_name ),4 );/* col3 len */
899
- pq_sendbytes (& buf ,snapshot_name ,strlen (snapshot_name ));
913
+ len = strlen (snapshot_name );
914
+ pq_sendint (& buf ,len ,4 );
915
+ pq_sendbytes (& buf ,snapshot_name ,len );
900
916
}
901
917
else
902
- pq_sendint (& buf ,-1 ,4 );/* col3 len, NULL */
918
+ pq_sendint (& buf ,-1 ,4 );
903
919
904
- /* plugin */
920
+ /* plugin, or NULL if none */
905
921
if (cmd -> plugin != NULL )
906
922
{
907
- pq_sendint (& buf ,strlen (cmd -> plugin ),4 );/* col4 len */
908
- pq_sendbytes (& buf ,cmd -> plugin ,strlen (cmd -> plugin ));
923
+ len = strlen (cmd -> plugin );
924
+ pq_sendint (& buf ,len ,4 );
925
+ pq_sendbytes (& buf ,cmd -> plugin ,len );
909
926
}
910
927
else
911
- pq_sendint (& buf ,-1 ,4 );/* col4 len, NULL */
928
+ pq_sendint (& buf ,-1 ,4 );
912
929
913
930
pq_endmessage (& buf );
914
931